exec

Runs an application.

exec <command line> [<show> [<wait> [<current directory>]]]

Remarks

Runs <command line> with /bin/sh -c, so shell syntax such as pipes and redirection can be used. Start Mac apps with the open command, e.g. 'open -a TextEdit readme.txt'.

Parameters

string <show> (optional default="show")
Accepted for compatibility with Windows macros, but not used ("hide", "minimize", "maximize" and "show" all work the same).
integer <wait> (optional default=0)
If it is 1, macro waits to finish the launched application. The exit code of the application stores the `result' system variable.
If it is not 1, macro launches the application and control is returned to macro.
string <current directory> (optional default="")
A current directory can be specified.
When omitted, the command runs in the folder of the macro file (setdir and changedir do not change it).

Return Value

System variable <result>
If integer value <wait> is 1
Value Meaning
-1 Failed to execute the application.
not -1 The exit code of the application

If integer value <wait> is not 1
Value Meaning
-1 Failed to execute the application.
0 Succeeded to execute the application.

Example

; Open a file in TextEdit.
exec 'open -a TextEdit readme.txt'

; Run a command in a given directory.
exec 'ls -l > list.txt' 'show' 0 '/Users/user/work'

; Wait for the command and check its exit code.
exec 'ping -c 1 192.0.2.1' 'hide' 1
if result = 0 messagebox 'OK' 'ping'
; Launch a shell script.
tmp='/bin/sh ~/upload.sh '
strconcat tmp username1
strconcat tmp ' '
strconcat tmp userpass1
strconcat tmp ' '
strconcat tmp address
messagebox tmp 'exec'
exec tmp
; Make a directory.
getenv "HOME" home
getdate logdir "log-%Y%m%d"
sprintf2 cmd 'mkdir -p "%s/Documents/%s"' home logdir
exec cmd "HIDE"