Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Run an AppleScript from the command line System
Want to run an AppleScript command real quick from Terminal? It's easy!

1. Run "osascript".
2. Type your script, for example:
tell application "Dock" to quit

launch application "Dock"
3. Type Control-D when done.

You can also supply a filename to "osascript" to run the script inside, and you can compile—but not run—script files using "osacompile".
  • Currently 2.75 / 5
  You rated: 1 / 5 (4 votes cast)

Run an AppleScript from the command line | 5 comments | Create New Account
Click here to return to the 'Run an AppleScript from the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use alias or full path for this to work!
Authored by: rshaw on May 06, '01 10:54:56PM

Please be aware, the above tip only works correctly if you run the "osascript" command with a full path, or from an alias. The man page states:


o osascript will not work correctly if it is found using your $PATH.
You must give the full path, i.e., /usr/bin/osascript.

You can either call the command as "/usr/bin/osascript", or create an alias in your .tcshrc file like this:

alias osascript /usr/bin/osascript

Without calling it full path or with an alias like above, you will get an error like this:

Syntax error -1750. Couldn't get error text because of error -1750.

Running it full path fixes that.

[ Reply to This | # ]
Doing this in one fell swoop
Authored by: sjonke on May 14, '01 02:44:20PM

If you want to run an Applescript command in one fell swoop, you can pipe in output from echo. For example, to launch the OS X application OmniWeb you can type in this:

echo 'tell application "OmniWeb" to activate' | /usr/bin/osascript

I'm no Unix expert, this is just a way I've found to do it - is there a better way (other than piping in echo) to get input into a Unix utility like this?

[ Reply to This | # ]
Running scripts remotely?
Authored by: sjonke on May 14, '01 03:52:37PM

Regarding my previous comment, never mind. Here is the right way to do it:

/usr/bin/osascript 'tell application "OmniWeb" to quit'

Anyway, is there any way to get osascript to work when logged in (ssh) remotely? When I try this, I get various errors. For example if I try to tell the Finder to quit I get the error "Finder got an error: Application isn't running. (-600)", however it clearly is running.

[ Reply to This | # ]
Running scripts remotely?
Authored by: sahmad on Oct 12, '01 09:16:27PM

I have been having the same exact problem when trying to run applescripts using 'rsh' from a remote machine.

Any envelope perl scripts are executed correctly by Darwin. Only the osascript/applescript section fails.

I can do rsh for other commands but not osascript related stuff. Is there some sort of built-in protection?

This really limits my ability to control automation on OSX macs. We currently do such tasks on MacOS9.X machines.

Any pointers will be appreciated!

[ Reply to This | # ]
Running scripts remotely? (yes!)
Authored by: rajiv on Nov 01, '01 03:51:36PM
if you don't need to craft the script on the command line and can put a self-running script on the mac, you can just use the 'open' command. check out Securely run remote AppleScripts for details.

[ Reply to This | # ]