AppleScript Programming/Shell Programming
Appearance
AppleScript can interact with UNIX shell scripts in a couple of ways. AppleScript can call UNIX shell scripts and utilities using the "do shell script" command. UNIX shell scripts can call the "osascript" utility to execute AppleScript code.
AppleScript command "do shell script"
[edit | edit source]To run shell commands from Applescript:
do shell script "afplay /System/Library/Sounds/Glass.aiff"
The user would hear a sound.
Shell command "osascript"
[edit | edit source]The osascript utility allows shell scripts to execute Applescript code in three different ways.
- Line by line from within a shell script using the
osascript -e
- Specify a plain text file or compiled script file using
osascript filename
. - Through the standard input.
For example, the following command in a shell script or at a prompt, will open a Mac OS X dialog box and wait for the user to respond:
osascript -e 'tell app "System Events" to activate' -e 'tell app "System Events" to display dialog "Hello, world!"'
The user would see: