Overview
Action: This action, as the name implies, executes an AppleScript allowing the user to pass parameters to the AppleScript's run
handler.
About AppleScript Run Handlers
The action essentially executes the following AppleScript statement:
run script %script_file% with parameters %parameters%
However, it first parses the parameters and ensures they are sent to the script in a useful manner, preserving international characters, and converting an inline-delimited list of parameters to an AppleScript list.
The script to be executed will possess a run
handler, which will receive the parameters in one of two ways, depending how the run
handler is declared.
The first way is to specify a single variable that can receive an arbitrary input:
on run args
Here, args
(which can be named however one wishes) will receive the parameters as an ordered list. Using the values from the above screen shot, args
will contain the following items when the action is triggered by its hotkey and the inline delimiter is set to comma:
{ "Hello World",
"~/Dropbox/File Requests/Music",
"ββ₯βT",
{"1", "1", "2", "3", "5", "8", "13"},
"Anders Jonas Γ
ngstrΓΆm" }
Note that item 4 of args
is itself a list, containing 7 items. If the inline delimiter is set to slash, the contents of args
would be:
{ "Hello World",
{"~", "Dropbox", "File Requests", "Music"},
"ββ₯βT",
"1,1,2,3,5,13",
"Anders Jonas Γ
ngstrΓΆm" }
where item 4 of args
is now a unary string value, but item 2 of args
is a list containing 4 items.
The second way to define the run
handler is to specify a list of variables, which restricts the number of parameters that can be passed to, and stores them individually:
on run {hello, filepath, trigger, fibonacci, angstrom}
Here is the content of each variable, firstly using the comma delimiter, then secondly using the slash delimiter:
If the run
handler specifies more parameters than are supplied, AppleScript will throw an error. If the run
handler specifies fewer parameters than are supplied, the remaining parameters are disregarded. For example, if the above action executes an AppleScript containing the following run
handler, using the same parameters as above:
on run {input, parameters}
then the value of input
will be "Hello World"
, and the value of parameters
will either be the string "~/Dropbox/File Requests/Music"
or the list {"~", "Dropbox", "File Requests", "Music"}
, depending on the inline delimiter selection.
Input: The AppleScript to be executed is specified by supplying a path to a .scpt
or .applescript
file in the field labelled Script File, which can include text tokens. The parameters are listed in the text box labelled Parameters. Each parameter is written on a single line, and may be a unary value or a list. A list of values is delimited by a single character chosen from the Inline Delimiter dropdown list. The default delimiter is a comma. A single space may optionally follow each delimiter, and will be disregarded during parsing. Therefore, the comma-delimited set of values 1,1,2,3,5,8,13
is the same as 1, 1, 2,3,5, 8,13
(however, the unary string expressions of these two would remain "as is"). Multiple spaces following a delimiter are retained, but one is always lost in parsing, i.e. two spaces become one, three become two, etc. The exception to this is when the chosen delimiter is the space
character: this can produce unusual results if more than two spaces are inserted between list items. Parameters may contain text tokens and international characters.
Output: The action returns the result of the AppleScript following its execution. This result may be ignored, displayed in a window, displayed in a notification, saved to a variable, or copied to the clipboard.
Run AppleScript With Specified Parameters.zip (48.2 KB) [ UPDATED: 2018-07-15 ]
Changes
Parameters are now coerced from their string values to the most suitable AppleScript type class object before being sent to the run
handler of the receiving script. Coercions take place on numerical, boolean, "null" and "missing value" parameters, and on parameters that are recognised as one of the following AppleScript constants: pi
, yes
, and no
. Leading and/or trailing white space doesn't prevent the type classing. A parameter of zero length is converted to missing value
.