File associations in OS X: doesn't pass filename in args?

722 views Asked by At

I am packaging an application into a .app directory for "drag install" or whatever it's called and I have a weird iessue with file association. I set my application as a viewer for .xyz files, and the system does start my app when I double click that file; the only problem is that the path of the file I clicked is nowhere in the args[], there's only one parameter that is something like ~psn_0_901340 and I think is a timestamp because it changes every time.

So... what am I supposed to do? I've been sitting here for 2 hours straight and can't find a solution.

1

There are 1 answers

1
AudioBubble On

I think what you want is an AppleScript droplet.

A shortened version of the AppleScript from that link:

on open dropped_files
    set the_command to quoted form of POSIX path of (path to resource "script.sh")
    set file_list to ""
    repeat with file_path in dropped_files
        set file_list to file_list & " " & quoted form of POSIX path of file_path
    end repeat
    set the_command to the_command & file_list
    do shell script the_command
end open

Export as an application using Script Editor. Place script.sh in the Resources folder.

Add your file extension associations to Info.plist. You may need to launch or move the droplet before OS X notices the change & allows you to double-click files.

If you want to launch Terminal or capture the script output, see the full AppleScript.