На MAC O.S., как получить имя файла, который был сброшен на скрипт Apple, для загрузки JAR с именем файла в качестве аргумента JAR - PullRequest
2 голосов
/ 02 февраля 2010

В редакторе скриптов я написал команду для загрузки JAR.

сделать сценарий оболочки "cd / Desktop / RunJar /; java -jar RunMyJar.jar"

и сохранен как файл сценария как приложение. Когда я нажимаю на файл скрипта, jar запускается.

Мои требования

Я хотел бы получить имя файла, который был добавлен в файл скрипта, и хотел бы передать имя этого файла в качестве аргумента моей банке.

Я реализовал это в Windows, но не мог работать аналогично на MAC O.S.

В Windows

Я поместил BAT-файл в Boot JAR вместе с абсолютным именем файла, которое было сброшено в bat-файле в Windows. @echo% * выдаст мне список файлов, которые были добавлены в пакетный файл.

@ echo% * @Пауза java -jar RunMyJar.jar% *

Подобное я хотел бы реализовать в MAC O.S.

Спасибо.

Ответы [ 3 ]

2 голосов
/ 02 февраля 2010

Я нашел следующий пример по адресу: Фрагменты кода Apple Apple Бена :

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 голос
/ 02 февраля 2010

Вы также можете легко изменить мой ответ на аналогичный вопрос :

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
0 голосов
/ 02 февраля 2010

Добавить к ответу Павла

on open of finderObjects</p> <pre><code>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

конец открыт

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...