1

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
    Aren't you making some assumptions about how the associated file is passed to the app? – Droppy Jun 05 '15 at 12:23
  • Well, on all other OSes the file name is passed via command line, how does it work here? – Garrus Vakarian Jun 05 '15 at 12:28
  • See [this question](http://stackoverflow.com/questions/10179524/opening-a-file-by-double-clicking-it-in-objective-c), amongst others. – Droppy Jun 05 '15 at 12:30
  • It's a .sh script, btw – Garrus Vakarian Jun 05 '15 at 12:30
  • I don't see how it can work then. – Droppy Jun 05 '15 at 12:31
  • Is there a way to make a launcher or something that gets the event and then launches my app with the filename in the command line like every proper OS? – Garrus Vakarian Jun 05 '15 at 12:39
  • 2
    I suggest reading Apple's documentation on [Launch Services](https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCIntro/LSCIntro.html) – TheDarkKnight Jun 05 '15 at 12:40
  • "proper OS"? Like what? – Droppy Jun 05 '15 at 12:40
  • Like EVERY other OS on the planet! – Garrus Vakarian Jun 05 '15 at 12:41
  • I mean, I don't wanna start an OS war but come on, I'm wasting so much time on such simple things... – Garrus Vakarian Jun 05 '15 at 12:41
  • So what other O/Ss support you packaging a shell script as an app and having file associations work properly? – Droppy Jun 05 '15 at 12:44
  • Pretty much every GNU/Linux distro, and I didn't check, but I think even Windows installer can do that – Garrus Vakarian Jun 05 '15 at 12:45
  • I'll give you 50 bucks if you can make that launcher :) I'm THAT frustrated – Garrus Vakarian Jun 05 '15 at 12:47
  • 2
    Garrus, you're not helping yourself, as your question is badly worded. "*packaging an application into a .app directory for "drag install" or whatever it's called*" - this makes no sense, particularly in the context of the rest of the question. You then comment "*It's a .sh script*", indicating you've missed necessary information from the question. I suggest taking time to think about what you're asking and edit and re-write the question to clearly explain your problem. [Well-written questions](http://stackoverflow.com/help/mcve) attract more people to answer. – TheDarkKnight Jun 05 '15 at 12:53

1 Answers1

1

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.