开发者

AppleScript to run .jar and pass name of dropped file as argument

开发者 https://www.devze.com 2023-02-07 22:30 出处:网络
I want to run a jar file that has a filename as argument. This filename should be the one of a file that is dropped onto the .app (the AppleScript)

I want to run a jar file that has a filename as argument. This filename should be the one of a file that is dropped onto the .app (the AppleScript)

I'开发者_如何学Gom a newbie in AppleScript, so any help would be appreciated!

thanks!


I doubt that there is an AppleScript command to run the jar file, so instead you could run a snippit of shell scripting from within the AppleScript. For example:

on open jarFiles
    tell application "Finder"
        repeat with currentJar in jarFiles
            set the shellScript to "java -jar " & ¬
                quoted form of ((name of currentJar) as text)
            do shell script shellScript
        end repeat
    end tell
end open

This example will open one or more dropped jar files. Note that the explicit line of code, tell application "Finder", means that the Finder's alias type will be used (which is necessary to get the name of the currentJar successfully.

The on open handler is the handler that is run on the event that the user drops one or more files onto the AppleScript (with the files being pased to the first argument, name jarFiles in this case).

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消