How to run a multiline AppleScript script from a Unix shell script (osascript)

This little example shows the syntax of how to run some AppleScript/osascript from a Unix shell script on a Mac OS X system:

#!/bin/sh

osascript <<EOF
tell application "Safari"
  close window 1
end tell
EOF

Just put your AppleScript in between the EOF parts, save it to a file, make the file executable, and this gives you a nice way to run a multiline AppleScript script from a shell script.

Here’s another example of what this looks like:

#!/bin/sh

osascript <<EOF
tell application "Safari" to activate
tell application "Safari"
    set bounds of front window to {300, 30, 1600, 1100}
end tell
EOF