On MAC OS, how to get the name of files that were deleted on an apple script to load a JAR with the file name as a JAR argument

In the Script editor, I wrote a command to load the JAR.

make shell Script "cd / Desktop / RunJar /; java -jar RunMyJar.jar"

and saved as a Script file as an application. When I click on the script file jar get run.

My requirement

I would like to get the name of the file that was dumped into the Script file, and would like to pass the name of this packed file as an argument to my bank.

I implemented this on Windows, but could not work similarly on MAC OS

In windows

I put the BAT file in the Boot JAR along with the absolute name of the file that was reset in the bat file on the windows. @ echo% * will provide me with a list of files that were deleted in the batch file.

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

Similarly, I would like to implement in MAC OS

Thank.

+2
source share
3 answers

To add to Paul's answer

on open of finderObjects

repeat with currFile in finderObjects
   -- ok, we have our current item. But it an "alias": a Mac OS path
   -- not a POSIX path
   set unixPath to POSIX path of currFile

   set base to do shell script "dirname " & unixPat
   set fname to do shell script "basename " & unixPath
   -- you could ask the Finder to give this to you too -- I'll use this way because
   -- I'm guessing it more familiar to you

   do shell script "cd '" & base & "';" & " java -jar " & fname
end repeat  

end open Code>

0
source

I found the following example: 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 info
    if folder of (info for i) is true then -- process folder 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
+2
source

You can also easily change your 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
+1
source

Source: https://habr.com/ru/post/1731062/


All Articles