views:

98

answers:

3

In Script editor i have written a command to boot the JAR.

do shell script "cd /Desktop/RunJar/; java -jar RunMyJar.jar"

and Saved as script file as a Application. When i click on script file jar get run.

My requirement

I would like get the name of file that has been dropped onto the script file and would like to pass the name of that dropped file as an argument to my jar.

I have implemented this in Windows but could not working similar on MAC O.S.

On Windows

I have placed a BAT file to Boot JAR along with the absolute file name, that has been dropped on the bat file on windows. @echo %* will give me the list of files that has been dropped onto Batch file.

@echo %* @pause java -jar RunMyJar.jar %*

Similar i would like to implement in MAC O.S.

Thanks.

+1  A: 

I found the following example at: Ben's AppleScript Snippets:

on open of finderObjects -- "open" handler triggered by drag'n'drop launches
  repeat with i in (finderObjects) -- in case multiple objects dropped on applet
    displayName(i) -- show file/folder's info
    if folder of (info for i) is true then -- process folder's contents too
      tell application "Finder" to set temp to (entire contents of i)
      repeat with j in (temp)
        display dialog j as string -- example of doing something with each item
      end repeat
    end if
  end repeat
end open
Paul R
Thank you very much
A: 
RyanWilcox
Thank you very much
A: 

You can also easily modify my answer to a similar question:

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
Philip Regan
Thank you very much