We recommend following these steps for those with the following operating systems running on a Mac: macOS 10.13 High Sierra, macOS 10.14 Mojave, and macOS 10.15 Catalia onward. It isn't always possible to download these Xcode Command Line Tools, following these steps, on Mac’s running older operating systems. However, keep in mind that on systems using SELinux, you may run into issues. For more information, read here. Running Mac command-line apps on Linux. Software in Darling can be installed in two ways: with DMG files or PKG files. To start installing software, enter the Darling shell with the command below.
This week the irrepressible Knightwise of knightwise.com sent in an awesome tip via audio, and it’s too good not to share in text as well. I’ll do my best to do it justice. I’ll start with the problem to be solved (of course) and then give a little bit of background and then his tip. Finally, I’ll give you bonus tip from me.
The problem to be solved is finding the easiest way to reinstall apps you’ve previously downloaded from the Mac App Store, especially when doing a nuke and pave, or moving to a new Mac but you don’t want to bring along the cruft you’ve collected over the years.
Homebrew
To follow along with Knightwise’s tip, you’ll need to know about Homebrew. Homebrew is a free and open-source, command-line package management system that simplifies the installation of applications on macOS.
The installation of Homebrew on your Mac is done of course via the command line. Navigate to brew.sh in your web browser and you’ll see one long command on the page. It looks scary but simply open up the Terminal, paste in the command, and it will install Homebrew and you’ll be ready to play with Knightwise’s tip.
Once you’ve installed Homebrew, installing apps via Homebrew is accomplished by simply typing
brew install followed by the name of the app.
mas
Now back to our problem to be solved. The packaged app you want to install is called mas, which is short for Mac App Store. To install mas, you simply type
brew install mas . You’ll see a download of a compressed gzip file and a couple of seconds later it’s installed.
Now that you have mas installed, you can tell it to list all of the apps you have installed on your Mac that came from the Mac App Store. Simply type
mas list . You’ll get a list with a long number in the first column, followed by the name of the app and the currently installed version. It’s a beautiful thing.
The long number is the code the Mac App Store uses to identify apps. If you’ve ever clicked on a link to take you directly to an app in the Mac App Store, in that link is this same long number. Let’s demonstrate this by example. I can see Yoink in my list generated by mas. Next to Yoink it says 457622435. If you go into the Mac App Store and search for Yoink, there’s a little downward chevron next to Buy (or Open if you already have it installed). If you click on that chevron, you can choose Copy Link. I’ll paste the link in the shownotes as plain text: https://itunes.apple.com/us/app/yoink-improved-drag-and-drop/id457622435?mt=12. You can see near the end of the link it says id followed by the same digits we saw in the mas listing. It’s good to understand the reason for that number because we’re actually going to be using it with mas.
Using the simple command
mas install followed by the number, we can install any app we’ve previously acquired through the Mac App Store.
To demonstrate mas, I decided to uninstall and reinstall an app for you. I started by deleting Yoink using AppDelete (mas doesn’t delete apps). Then I re-ran
mas list to verify Yoink was no longer in the list. Now here’s the fun part. I typed mas install 457622435 and it installed Yoink for me without ever opening the Mac App Store!
It’s truly amazing to me that this app is able to send the right code to the Mac App Store and tell it what to do. The documentation for mas is very clear, you must have already bought (or downloaded for free) the app in the Mac App Store in order to install with mas.
You also have to be logged into the Mac App Store to do this as well. https://mfbnze.weebly.com/mac-audio-routing-app.html. If you happen to be logged out, you can even sign into the Mac App Store from mas. simply type
mas signin youremailaddress and you’ll be prompted for your Apple ID password and you’re in. For some reason this didn’t work for me, mas insisted that I was already logged in when the Mac App Store thought I was not. Made me sad that I had to do it the old-fashioned way.
Here’s another great command. How annoying is it to try to find an app you’ve previously acquired from the Mac App Store? What order are they listed in anyway??? It’s not alphabetical, I know that for sure, and it’s not exactly time-based either. And of course Apple doesn’t let you search for apps within the Purchased tab. I know you can search from the main pages of the Mac App Store and if you’ve bought it before it hopefully says download instead of buy but I’ve had that trick me up before.
With mas, you can enter into your Terminal window
mas search Yoink and it will return the code for Yoink ready for you to install again. That’s got to be about 236 times faster than finding it in the Mac App Store.
Want to know what apps need to be updated on your Mac? Type
mas outdated . I didn’t even realize I had pending updates but I found out Slack, Amadeus Pro, Telegram and Paprika all want updates right now.
Let’s take it up a notch and instead of launching the Mac App Store to actually do the updates, let’s update the apps right from mas. Type
mas upgrade and it upgrades all of your out-of-date apps. I don’t know about you, but launching the Mac App Store and waiting ages for it to animate to do the installations has become quite the bore. Doing it with mas was much faster and somehow it felt like cheating!
If you’re of the script-writing persuasion, you can see how fun it would be to write a script to download the list of apps and their codes to a file and then run that list as an input on a new Mac.
I mentioned the Previous Purchases tab earlier, If an application is no longer in the Mac App Store and so no longer in your Previous Purchases, mas won’t be able to install it.
When you forget all of the commands I taught you, or to look for more commands, type
mas help and you’ll get a full listing. If you’d like to read more or even download the source code for mas, go to github.com/…
Cake Brew
I promised at the beginning that I had a little tip for you to add to all of this. I’m able to remember the command
brew install but I don’t actually know any of the other brew commands. I could learn them but I’m not a frequent brewer so I haven’t bothered to memorize them. One thing you might want to learn to do is to keep the apps updated that you install from brew.
Enter Cake Brew. I learned about Cake Brew from John F Braun on the Mac Geek Gab. Cake Brew is a GUI interface for Homebrew. I know, it’s counterintuitive to use a GUI when we’re going to all this effort to use the command line, right? But I’m going to use Knightwise’s tag line, “Making technology work for you.” If a GUI works for you, use it!
Cake Brew shows you what apps you have installed (it calls them formulas for some reason). With the click of a button you can uninstall an app, but there’s also an Outdated section. With the click of a button in that tab you can update all of your apps.
I think Cake Brew is a slick little app and it helps me keep track of my Homebrew apps without having to remember the commands.
Many thanks to Knightwise for telling us about mas and I hope you have as much fun with it as I am.
Historically, the command line interface provided a way to manipulate a computer over simple, text-based connections. In the modern era, in spite of the ability to transmit graphical user interfaces over the Internet, the command line remains a powerful tool for performing certain types of tasks.
As described previously in Before You Begin, most users interact with a command-line environment using the Terminal application, though you may also use a remote connection method such as secure shell (SSH). Each Terminal window or SSH connection provides access to the input and output of a shell process. A shell is a special command-line tool that is designed specifically to provide text-based interactive control over other command-line tools.
In addition to running individual tools, most shells provide some means of combining multiple tools into structured programs, called shell scripts (the subject of this book).
Different shells feature slightly different capabilities and scripting syntax. Although you can use any shell of your choice, the examples in this book assume that you are using the standard OS X shell. The standard shell is
bash if you are running OS X v10.3 or later and tcsh if you are running an earlier version of the operating system.
The following sections provide some basic information and tips about using the command-line interface more effectively; they are not intended as an exhaustive reference for using the shell environments.
Note: This appendix was originally part of Mac Technology Overview.
Basic Shell Concepts
Before you start working in any shell environment, there are some basic features of shell scripting that you should understand. Some of these features are specific to OS X, but most are common to all platforms that support shell scripting.
Running Your First Command-Line Tool
In general, you run command-line tools that OS X provides by typing the name of the tool. (The syntax for running tools that you’ve added is described later in this appendix.)
For example, if you run the
ls command, by default, it lists the files in your home directory. To run this command, type ls and press Return.
How To Run Mac App From Command Line Command
Most tools also can take a number of flags (sometimes called switches). For example, you can get a “long” file listing (with additional information about every file) by typing
ls -l and pressing Return. The -l flag tells the ls command to change its default behavior.
Similarly, most tools take arguments. For example, to show a long listing of the files on your OS X desktop, type
ls -l Desktop and press Return. In that command, the word Desktop is an argument that is the name of the folder that contains the contents of your OS X desktop.
In addition, some tools have flags that take flag-specific arguments in addition to the main arguments to the tool as a whole.
Specifying Files and Directories
Most commands in the shell operate on files and directories, the locations of which are identified by paths. The directory names that make up a path are separated by forward-slash characters. For example, the Terminal program is in the
Utilities folder within the Applications folder at the top level of your hard drive. Its path is /Applications/Utilities/Terminal.app .
The shell (along with, for that matter, all other UNIX applications and tools) also has a notion of a current working directory. When you specify a filename or path that does not start with a slash, that path is assumed to be relative to this directory. For example, if you type
cat foo , the cat command prints the contents of the file foo in the current directory. You can change the current directory using the cd command.
Finally, the shell supports a number of directory names that have a special meaning.
Table A-1 lists some of the standard shortcuts used to represent specific directories in the system. Because they are based on context, these shortcuts eliminate the need to type full paths in many situations.
File and directory names traditionally include only letters, numbers, hyphens, the underscore character (
_ ), and often a period (. ) followed by a file extension that indicates the type of file (.txt , for example). Most other characters, including space characters, should be avoided because they have special meaning to the shell.
Although some OS X file systems permit the use of these other characters, including spaces, you must do one of the following:
For example, the path name
My Disk can be written as 'My Disk' , 'My Disk' , or My Disk .
Single quotes are safer than double quotes because the shell does not do any interpretation of the contents of a single-quoted string. However, double quotes are less likely to appear in a filename, making them slightly easier to use. When in doubt, use a backslash before the character in question, or two backslashes to represent a literal backslash.
For more detailed information, see Quoting Special Characters in Flow Control, Expansion, and Parsing.
Accessing Files on Additional Volumes
On a typical UNIX system, the storage provided by local disk drives is presented as a single tree of files descending from a single root directory. This differs from the way the Finder presents local disk drives, which is as one or more volumes, with each volume acting as the root of its own directory hierarchy. To satisfy both worlds, OS X includes a hidden directory,
Volumes , at the root of the local file system. This directory contains all of the volumes attached to the local computer.
To access the contents of other local (and many network) volumes, you prefix the volume-relative path with
/Volumes/ followed by the volume name. For example, to access the Applications directory on a volume named MacOSX , you would use the path /Volumes/MacOSX/Applications .
Note: To access files on the boot volume, you are not required to add volume information, since the root directory of the boot volume is
/ . Including the volume information still works, though, so if you are interacting with the shell from an application that is volume-aware, you may want to add it, if only to be consistent with the way you access other volumes. You must include the volume information for all volumes other than the boot volume.
Mac Os Run App From Command LineInput And Output
https://mfbnze.weebly.com/fanny-mac-os-app.html. Most tools take text input from the user and print text out to the user’s screen. They do so using three standard file descriptors, which are created by the shell and are inherited by the program automatically. These standard file descriptors are listed in Table A-2.
To learn more about working with these descriptors, including redirecting the output of one tool to the input of another, read Shell Input and Output.
Terminating ProgramsMac Run App From Command Line
To terminate the currently running program from the command line, press Control-C. This keyboard shortcut sends an abort (
ABRT ) signal to the currently running process. In most cases this causes the process to terminate, although some tools may install signal handlers to trap this signal and respond differently. (See Trapping Signals in Advanced Techniques for details.)
In addition, you can terminate most scripts and command-line tools by closing a Terminal window or SSH connection. This sends a hangup (
HUP ) signal to the shell, which it then passes on to the currently running program. If you want a program to continue running after you log out, you should run it using the nohup command, which catches that signal and does not pass it on to whatever command it invokes.
Frequently Used Commands
Shell scripting involves a mixture of built-in shell commands and standard programs that run in all shells. Although most shells offer the same basic set of commands, there are often variations in the syntax and behavior of those commands. In addition to the shell commands, OS X also provides a set of standard programs that run in all shells.
Table A-3 lists some commands that are commonly used interactively in the shell. Most of the items in this table are not specific to any given shell. For syntax and usage information for each command, see the corresponding man page. For a more in-depth list of commands and their accompanying documentation, see OS X Man Pages.
Environment Variables
Some programs require the use of environment variables for their execution. Environment variables are variables inherited by all programs executed in the shell’s context. The shell itself uses environment variables to store information such as the name of the current user, the name of the host computer, and the paths to any executable programs. You can also create environment variables and use them to control the behavior of your program without modifying the program itself. For example, you might use an environment variable to tell your program to print debug information to the console.
To set the value of an environment variable, you use the appropriate shell command to associate a variable name with a value. For example, to set the environment variable
MYFUNCTION to the value MyGetData in the global shell environment you would type the following command in a Terminal window:
When you launch an application from a shell, the application inherits much of its parent shell’s environment, including any exported environment variables. This form of inheritance can be a useful way to configure the application dynamically. For example, your application can check for the presence (or value) of an environment variable and change its behavior accordingly. Different shells support different semantics for exporting environment variables, so see the man page for your preferred shell for further information.
Child processes of a shell inherit a copy of the environment of that shell. Shells do not share their environments with one another. Thus, variables you set in one Terminal window are not set in other Terminal windows. Once you close a Terminal window, any variables you set in that window are gone.
If you want the value of a variable to persist between sessions and in all Terminal windows, you must either add it to a login script or add it to your environment property list. See Before You Begin for details.
Similarly, environment variables set by tools or subshells are lost when those tools or subshells exit.
Running User-Added Commands
As mentioned previously, you can run most tools by typing their name. This is because those tools are located in specific directories that the shell searches when you type the name of a command. The shell uses the
PATH environment variable to control where it searches for these tools. It contains a colon-delimited list of paths to search--/usr/bin:/bin:/usr/sbin:/sbin , for example.
If a tool is in any other directory, you must provide a path for the program to tell it where to find that tool. (For security reasons, when writing scripts, you should always specify a complete, absolute path.)
For security reasons, the current working directory is not part of the default search path (
PATH ), and should not be added to it. If it were, then another user on a multi-user system could trick you into running a command by adding a malicious tool with the same name as one you would typically run (such as the ls command) or a common misspelling thereof.
For this reason, if you need to run a tool in the current working directory, you must explicitly specify its path, either as an absolute path (starting from
/ ) or as a relative path starting with a directory name (which can be the . directory). For example, to run the MyCommandLineProgram tool in the current directory, you could type ./MyCommandLineProgram and press Return.
With the aforementioned security caveats in mind, you can add new parts (temporarily) to the value of the
PATH environment variable by doing the following:
If you want the additional path components to persist between sessions and in all Terminal windows, you must either add it to a login script or add it to your environment property list. See Before You Begin for details.
Running ApplicationsMac Command Line Tutorial
To launch an application, you can generally either:
Note: As a general rule, if you launch a GUI application from a script, you should run that script only within Terminal or another GUI application. You cannot necessarily launch an GUI application when logged in remotely (using SSH, for example). In general, doing so is possible only if you are also logged in using the OS X GUI, and in some versions of OS X, it is disallowed entirely.
Learning About Other Commands
At the command-line level, most documentation comes in the form of man pages (short for manual). Man pages provide reference information for many shell commands, programs, and POSIX-level concepts. The manual page
manpages describes the organization of manual, and the format and syntax of individual man pages.
To access a man page, type the
man command followed by the name of the thing you want to look up. For example, to look up information about the bash shell, you would type man bash . The man pages are also included in the OS X Developer Library (OS X Man Pages).
You can also search the manual pages by keyword using the
apropos command.
Note: Not all commands and programs have man pages. For a list of available man pages, look in the
/usr/share/man directory or see OS X Man Pages in the OS X Developer Library.
Run Osx App From Command Line
Most shells have a command or man page that displays the list of commands that are built into the shell (builtins). Table A-4 lists the available shells in OS X along with the ways you can access the list of builtins for the shell.
Mac Command Line List
Copyright © 2003, 2014 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2014-03-10
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |