Using macOS I have a command line executable that I can, following some advice about using Automator, make usable as an application, with the code:
on run {input, parameters}
tell application "Terminal"
activate
do script with command "myname"
end tell
return input
end run
where myname (not the real name) is an alias I have to the executable I want to run. That does create an executable I can double-click on.
I then want to associate the extension .myname with that application. Which I can do. But when I double-click on the file it runs my application without any reference to the file. I want to run the executable with a single command line parameter, the name of the file I double clicked on. Which I hope/guess I can do by changing “myname” to something like “myname ???” – but what is the ???
4
An Automator application passes the input items to the workflow. For a Run AppleScript action, it receives those as a list in the input
parameter. The action can also check for an empty input and put up a choose dialog if the application is just double-clicked.
Note that Terminal’s do script
command is a string (there is no with
property), so you would need to build the full command line statement, for example:
on run {input, parameters} -- example
if input is {} then set input to (choose file with prompt "Choose file items:" with multiple selections allowed)
set command to "/bin/ls -l " -- path to command - note that a default $PATH is used
set args to ""
repeat with anItem in input -- create an argument string from the input list items
set args to args & space & quoted form of POSIX path of anItem
end repeat
tell application "Terminal"
activate
try -- use front window
do script command & args in front window
on error -- no window, so use a new one
do script command & args
end try
end tell
return input -- pass items on to other actions
end run
2