OS X: Specifying custom command line invocation of program as application for opening files on double click I'm primarily a Linux user who recently acquired a MacBook Air and I'm currently desperately trying to find out whether there's an equivalent for Linux's desktop definition files, where you can define an application by its command line invocation, with an optional placeholder for the file that X11 will pass to it when a file of file type associated with that application is double-clicked.

E.g. on Linux, I can set .txt files to be opened with a specific command line invocation of emacsclient like so:

emacsclient -c -a "" %f


where %f is the placeholder that will get replaced by the path to the actual file you double-click on. (In general, Linux file managers allow you to specify this command line in the File info window.)

Is there any simple way to achieve this on OS X? I've tried tinkering with AppleScript, as well as Google around for a solution, but to no avail. I probably still need to build up my Apple-technology-related knowledge and vocabulary, so as to be able to ask the right questions with the right words -- so please bear with me...
To my knowledge, there is nothing to automatically run any script on double-script (I am most likely wrong). The best solution I've found is Automator. It's preinstalled. You want  to create a service, which will place scripts into a context menu (right-clicking on file). For your actions, you want to find the action "Run Shell Script". From there, you can have it receive input from Finder, such as file paths and directory paths. If you pass input to stdin, the variable you will use in the shell script is $@.

if [[ ! -d "$@" ]]
then
    emacsclient -c -a "" $@;
    exit
fi


I do not know if that script is entirely correct, but it should put on you the right track.