home ~ projects ~ socials

Run A Multiline AppleScript On The Command Line

AppleScipts are generally at least three lines. For example:

tell application "Sublime Text"
    activate
  end tell

The line ending acts as he seperator. You can't use ; like with javascript to make a single line command. Instead, you can pass each line with it's own -e flag.

For example:

osascript -e 'tell application "Sublime Text"' -e 'activate' -e 'end tell'

Another option (and the one I generally go with) is to use javascript instead of applescript.

osascript -l JavaScript -e "Application('Sublime Text').activate()"
-- end of line --