Shell Call Construction
Structure
A shell command typically begins with the command name.
| Command name letter case isn't usually important, however expecting case sensitivity at all times is wise. |
In shell speak, a switch defines command behavior.
Capture image of window in interactive mode to clipboard.
on mouseup
put shell("screencapture -ciW ") into junk
end mouseup
A command may allow one or more pathname parameters.
Capture image of window in interactive mode and save to png file on user's desktop.
on mouseup
put shell("screencapture -iW ~/Desktop/windowImage.png ") into junk
end mouseup
Stringing Commands Together.
When one or more commands are strung together in a single call, commands are delimited by a control operator. Terminating the final command isn't usually required.
Semicolon and Pipe.
A | character, 'pipe' in shell parlance, pipes output of previous command to the next.
Display local and GMT.
on mouseup
alert Sheet shell("date +'%a, %e %b %Y %T %Z' ; date -u +'%a, %e %b %Y %T %Z' | perl -pe chomp ;")
end mouseup
| Examples below not functioning properly |
Double pipe (logical OR)
The command(s) following || are executed only if a previous command has failed.
function shellCmdVersion
return shell(merge("[[commandName]] -v || [[commandName]] --version || echo 'Error!'"))
end shellCmdVersion
The following function returns command version info and help text, or displays error in console application.
function shellCmdVersionHelp cmdName
put merge("[[cmdName]] -v ; [[cmdName]] -h ") into cmd
put merge(" || [[cmdName]] --version ; [[cmdName]] --help ") after cmd
put merge(" || osascript -e 'tell application `console` to activate' ; ") after cmd
return shell(cmd)
end shellCmdVersionHelp
Double && (logical AND)
Need better example... results identical to script above.
function shellCmdVersionHelp cmdName
put merge("[[cmdName]] -v && [[cmdName]] -h ") into cmd
put merge(" || [[cmdName]] --version && [[cmdName]] --help ") after cmd
put merge(" || osascript -e 'tell application `console` to activate' ; ") after cmd
return shell(cmd)
end shellCmdVersionHelp
Variables may simplify construction of complex shell calls.
Comments (0)
You don't have permission to comment on this page.