How to Run AppleScript on Mac OS X with osascript -


Post Top Ad

Post Top Ad

Sunday, 21 August 2016

How to Run AppleScript on Mac OS X with osascript

Mac users can run an AppleScript from the command line if desired, using a script file or give osascript sentences using a plain text script. This can be useful for many purposes, but should be especially nice for users who spend time on the command line or performing remote management with ssh.

The command will run any script osascript OSA and while we are focusing on AppleScript, you can use osascript to run Javascript.

AppleScript file execution commands from the command line

To run a script file AppleScript Terminal in Mac OS, simply locate the osascript the file path .scpt command like this:

/ejemplo/directorio/a/AppleScript.scpt osascript

For example, if you saved this script to automatically connect to a VPN as a script file instead of an application, could signal the osascript command directly on the file to run. You can launch any file by simply pointing .scpt osascript command in the correct directory.

Running AppleScript script directly from Terminal

To run a specific AppleScript script or statement without having saved as .scpt file, you can simply use the -e flag then the single and double quotes necessary to quote correctly and exit the script.

Here we show some examples:

  osascript -e 'display dialog "Hello from" with title "Hello"' 

A dialog box will be displayed saying "Hello"

  osascript -e 'tell app "Finder" to make new Finder window' 

a new Finder window will open

  osascript -e "set volume 0" 

the system volume is muted.

Anyone interested in learning more about AppleScript can find a lot of information, syntax, commands and useful guidelines in implementing script editor that is included in   MacOS X and Mac OS.

No comments:

Post a Comment

Post Top Ad