在脚本编辑器中,我编写了一个启动JAR的命令。
执行shell脚本“cd / Desktop / RunJar /; java -jar RunMyJar.jar”
并将其另存为脚本文件作为应用程序。当我点击脚本文件jar时运行。
我的要求
我想获取已放到脚本文件中的文件名,并希望将该删除文件的名称作为参数传递给我的jar。
我已在Windows中实现此功能但在MAC O.S上无法正常工作
在Windows上
我已将BAT文件与绝对文件名一起放入Boot JAR,该文件名已被删除在Windows上的bat文件中。 @echo%*将为我提供已删除到批处理文件的文件列表。
@echo%* @暂停 java -jar RunMyJar.jar%*
类似我想在MAC O.S。
中实施感谢。
答案 0 :(得分:2)
我在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
答案 1 :(得分:1)
您也可以轻松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
答案 2 :(得分:0)
添加保罗的回答
on open of finderObjects
repeat with currFile in finderObjects
-- ok, we have our current item. But it's 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's more familiar to you
do shell script "cd '" & base & "';" & " java -jar " & fname
end repeat
repeat with currFile in finderObjects
-- ok, we have our current item. But it's 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's more familiar to you
do shell script "cd '" & base & "';" & " java -jar " & fname
end repeat