

The script is called from the Terminal command line like this: % histogram.rb somefile.For those who are unfamiliar with osascript, it’s a command line interface to AppleScript that allows you to execute AppleScripts and OSA language scripts from the terminal.

Excel data and chart generated by a Ruby script
Osascript commands for geektool 3.3.1 series#
If you omit it, a list of strings is flattened into a series of comma-delimited tokens: % osascript -ss -e 'tell app "Finder" to get name of every disk' '`įigure 25-1. If you include it, delimiters are used, as in the Script Editor, to show the nature of the result. The result of osascript is formatted differently depending on whether you supply the -ss flag. For example: % osascript -e 'tell app "Finder"' -e 'display dialog "Hello, world!"' -e 'end' The shell's usual quotational hoops will have to be jumped through the bash shell helps by permitting a literal string to be entered in ANSI-C form: % osascript -e $'tell app "Finder"\rdisplay dialog "Hello, world!"\rend'Īnother approach to entering a multiple-line script is to repeat the -e switch multiple times. To include the script text on the command line, use the -e switch. You can enter the script text manually after the osascript command: % osascript tell app "Finder" display dialog "Hello, world!" end ^D
Osascript commands for geektool 3.3.1 how to#
Here's how to execute a text file or a compiled script file (these are the same files we made earlier in connection with osacompile): % osascript textfile.txt % osascript compiledfile.scpt This command is the real key to bridging the gap between Unix and AppleScript from the Unix side. The osascript command executes a compiled script file, a text file, or text provided from the command line. Consult the osacompile man pages for more information. Further switches let you determine which fork the compiled script bytecode is saved into (the default is the resource fork see "Compiled Script File Formats" in Chapter 3) and the characteristics of a created applet (see "Applet Options" in Chapter 27). app extension makes an applet bundle, and otherwise you get a compiled script file. scptd extension makes a script bundle, the. The extension on the filename supplied in the -o parameter determines the type of file that's created the.

You can avoid the intermediate text file by including the script text as part of the osacompile command the ensuing discussion of osascript shows how. The result is a compiled script file compiledfile.scpt that can be opened in Script Editor, executed by a script runner, and so forth. For example: % cat > textfile.txt tell app "Finder" display dialog "Hello, world!" end ^D % osacompile -o compiledfile.scpt textfile.txt Osacompile takes as argument a text file, or some text provided on the command line, and generates a compiled script file or applet. In general, unless you are using other OSA scripting components, you'll have no need for osalang. You can use either of these two terms as a language specifier in calling the other two command-line tools, but their effect will be identical, because the GSC will treat AppleScript as the default component. The "Generic Scripting System" is the general front end to the OSA (what Chapter 3 calls the generic system component or GSC) "AppleScript" is the AppleScript scripting component in particular. Finally, we have the name of the component. Then comes a series of flags describing the capabilities of this scripting component (see the osalang man page for their meanings). (For example, if you use Script Debugger, you'll see AppleScript Debugger X and JavaScript.) The two four-letter codes identifying each component are used by OSA programmers, but typically won't arise in the context of your AppleScript experience.

If you have other OSA components installed, they will also appear. Osalang lists the scripting components present on your machine (see "The Open Scripting Architecture" in Chapter 3): % osalang -l ascr appl cgxervdh AppleScript scpt appl cgxervdh Generic Scripting System Three command-line tools are provided for accessing AppleScript from Unix osalang, osacompile, and osascriptof which osascript is the most important.
