Applescript, имена файлов POSIX и Mountain Lion
Пока я использовал Snow Leopard, я много раз использовал следующий шаблон при создании своих Applescripts:
on run args
set filePath to POSIX file (item 1 of args) as alias
...
end run
После обновления до Mountain Lion приведенный выше скрипт, похоже, выдает предупреждение:
2012-08-10 15:12:12.305 osascript[54131:303]
CFURLGetFSRef was passed this URL which has no scheme
(the URL may not work with other CFURL routines): path/to/input/file.ext
Может ли кто-нибудь просветить смысл ошибки?
2 ответа
Это должно прояснить проблему и решение. Итак, сначала с проблемой
TB1T-Bboot:$ cat tmp.applescript
tell application "Finder"
set MacOSpath to POSIX file "test-file" as alias
end tell
TB1T-Bboot:$ osascript tmp.applescript
2012-09-24 22:25:50.022 osascript[2564:707] CFURLGetFSRef was passed this URL which has no scheme (the URL may not work with other CFURL routines): test-file
alias TB1T-Bboot:Users:archive:test-file
TB1T-Bboot:$
Теперь без проблем:
TB1T-Bboot:$ cat tmp.applescript
tell application "Finder"
set MacOSpath to POSIX file "/Users/archive/test-file" as alias
end tell
TB1T-Bboot:$ osascript tmp.applescript
alias TB1T-Bboot:Users:archive:test-file
TB1T-Bboot:$
Так что жалуется, что путь относительный, а не абсолютный. Это предупреждение не появляется во льве.
Простым исправлением будет префикс пути с file:///
, Mountain Lion ожидает URL-адреса для всего, поэтому "голый" путь не сработает.
Например, если вы хотите /Users/RobertoAloi/file.txt you would pass in
Файл: /// Пользователи /RobertoAloi/file.txt`.
Подробную информацию о CFURLGetFSRef можно найти по адресу https://developer.apple.com/library/mac/#documentation/CoreFOundation/Reference/CFURLRef/Reference/reference.html.