osasubr - a OS X unix command-line utility to pass arguments to an applescript.

About osasubr (Version 1.00)

osasubr is a simple, freeware, OS X command-line utility to run an appleScript subroutine, passing it arguments.

osasubr is an improvement on osascript, because osasubr lets you pass arguments to an appleScript, and receives the result back as text coming in on standard in.

This program replaces Apple's osascript, a OS X unix command-line utility that lets you run an applescript.

You'll also want to look at Apple's Tech Note on do shell script, which explains how to call unix commands from appleScript.

This is freeware, C++ source included. (zlib/png license)

Usage: osasubr file subr [arg1 .. argn]

"osasubr" is a Unix command line program that takes as arguments:
file -- the name of the appleScript file to search
subr -- the name of the subroutine to execute
arg1..argn -- arguments to pass as strings to the appleScript subroutine

-- copy "osasubr" to "/usr/local/bin" Here is the Unix command:
cp osasubr /usr/local/bin
In some versions of the Unix shell, you'll need to type "rehash" for the shell to rebuild its RAM cache of current commands.

Example of usage: Given a file of appleScript subroutines, that you've saved as compiled scripts, like this one, named "mesg":
on mesg1(alert_message)
display dialog alert_message
end mesg1
on mesg3(alert_message, button1, button2)
set result to display dialog alert_message buttons {button1, button2}
button returned of result
end mesg3
from the Unix command line:

osasubr mesg mesg3 "Are we there yet?" yes no
will open the file mesg, and run the routine mesg3, passing the rest of the command line as arguments, arg1="Are we there yet", arg2=yes, arg3=no

You can pass a Unix (Posix) path for the file argument.

The return value of the appleScript subroutine is interpreted as a string and written to the standard output.

If an error occurs, the error code is the numeric return value passed from "osasubr" (0 means no error ocurred)

License agreement:

This program is under the zlib/png license, <http://www.opensource.org/licenses/zlib-license.php>

Copyright (c) 2003 David Phillip Oster

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.

3. This notice may not be removed or altered from any source distribution.

Note: if you use the Unix command "strip" on osasubr, then osasubr will stop working correctly (you can put up dialog boxes, but they won't respond to mouse clicks.)

Version 1.0

David Phillip Oster



May 2003


Download C++ Source Code

Page last modified April 25, 2005