views:

136

answers:

2

This AppleScript code gives the name of files that have been dropped onto the script. How do I do the same in an Objective-C app? Would an application written in Objective-C be able to boot the JAR file using the file name as an argument to JAR?

on open of theFiles -- Executed when files are dropped on the script

    set fileCount to (get count of items in theFiles)

    repeat with thisFile from 1 to fileCount
        set theFile to item thisFile of theFiles
        set theFileAlias to theFile as alias

        tell application "Finder"
                set fileInfo to info for theFileAlias
                set fileName to name of fileInfo

                -- something to this effect, but now that you have the file name,
                -- do what you will...
                do shell script "cd /Desktop/RunJar/; java -jar " & fileName

        end tell

    end repeat

end open

We need to replace this AppleScript with a compiled app that can run a JAR that has been dropped onto the compiled app.

+2  A: 

To get the path to the JAR file, your app must first implement Drag-and-Drop. See Drag and Drop Programing Topics for Cocoa (or as PDF)

NSResponder
1) An answer that consists solely of a link is generally considered bad practice. Stack Overflow aims to become _the_ repository of answers for _all_ questions, so if you link, copy some relevant quotes from the link and maybe elaborate. 2) If you do link to documentation (which isn't a bad thing in and of itself), don't use the term "RTFM," as it is very condescending and will turn a lot of people off. That's no way to help people out, is it?
Chris Lutz
Is this policy documented somewhere? The answers to questions go out of date. I'd much rather link to docs owned by a project when applicable. Furthermore, when people attempt to restate docs, they often make mistakes that aren't in the original.
Ken
@Ken: And links die in time, too. It's much better for someone to find outdated content than nothing.
Tamás Szelei
A: 

As for actually running the jar:

                do shell script "cd /Desktop/RunJar/; java -jar " & fileName

Use NSTask. The difference is that NSTask does not run a shell script; it runs the program (in this case, java) directly. You will need to set the task's working directory before running it.

Peter Hosey