In AppleScript, the
do shell script command is used to execute command-line tools. This command is implemented by the Standard Additions scripting addition included with OS X.
Calling Command-Line Tools
![]()
The Mac software update command we’re talking about is helpfully well named: softwareupdate. Here’s how to use it. Launch the Terminal application (which can be found in the /Applications/Utilities folder or by searching for it with Spotlight). From the Terminal, type softwareupdate -l (that’s a lowercase “L” and not the number one). This is the command that works on all Unix machines. I use it on Linux/Ubuntu, but it works in OS X as well. Type the following command in Terminal.app. $ g -o lab21 iterative.cpp -o is the letter O not zero. Lab21 will be your executable file. Iterative.cpp is your c file. After you run that command type the following in terminal to run.
The Terminal app in
/Applications/Utilities/ is scriptable and provides another way to execute command-line tools from scripts. https://ixtrjfe.weebly.com/blog/mac-app-photo-negative. https://everparent417.weebly.com/auto-tune-8-settings.html.
How To Execute App From Terminal Mac ShortcutExecuting Commands
The direct parameter of the
do shell script command is a string containing the shell code you want to execute, as demonstrated in Listing 39-1, which simply lists a directory.
APPLESCRIPT
Listing 39-1AppleScript: Executing a simple shell command that lists the contents of a directory
![]()
Since the direct parameter of
Listing 39-2AppleScript: Concatenating a command with a value
do shell script is a string, you can concatenate it with other strings at run time. Listing 39-2, for example, concatenates a shell command to a previously defined parameter value.
Quoting Strings
The shell uses space characters to separate parameters and gives special meaning to certain punctuation marks, such as
$ , ( , ) , and * . To ensure that strings are treated as expected—for example, spaces aren’t seen as delimiters—it’s best to wrap strings in quotes. This process is known as quoting. If your string contains quotes, they must also be escaped (preceded by a / character) so they are interpreted as part of the string. https://ixtrjfe.weebly.com/blog/reset-quickbooks-app-mac. Listing 39-3 shows an example of an error occurring as a result of a parameter that contains a space.
APPLESCRIPT
Best Mac Terminal AppListing 39-3AppleScript: An error resulting from a string containing a space
The easiest way to quote a string is to use the
quoted form property of the text class, as demonstrated in Listing 39-4. Download excel for mac 2011 free. This property returns the string in a form that’s safe from further interpretation by the shell, regardless of its contents.
APPLESCRIPT
Listing 39-4AppleScript: Quoting a string to prevent errors
More Information
For more information about the
do shell script command, see Commands Reference in AppleScript Language Guide and Technical Note TN2065.
Copyright © 2018 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2016-06-13
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |