2012-08-10 66 views
2

當我使用雪豹,我創建我的AppleScript時,多次使用以下模式:AppleScript的,POSIX文件名和山獅

on run args 
    set filePath to POSIX file (item 1 of args) as alias 
     ... 
end run 

升級到山獅後,上面的腳本似乎產生一個警告,但:

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 

任何人都可以啓發的錯誤的含義?

回答

4

這個發現應該澄清的問題和解決方案。因此,首先問題

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:$ 

所以它的抱怨,路徑是相對的,不是絕對的。這個警告不會出現在Lion中。

0

一個簡單的修復方法是在路徑前加上file:///。 Mountain Lion期望所有內容的URL,因此「裸體」路徑將無法使用。

例如,如果您需要/Users/RobertoAloi/file.txt you would pass in file:/// Users/RobertoAloi/file.txt`。

爲CFURLGetFSRef細節可以在https://developer.apple.com/library/mac/#documentation/CoreFOundation/Reference/CFURLRef/Reference/reference.html

+0

雪豹會抱怨前綴嗎?由於我切換到ML,因此無法再測試它。 – 2012-08-10 13:28:46

+0

另外,這似乎並不適合我,但我可能在錯誤的方式前綴。你能舉個例子嗎? – 2012-08-10 13:42:44

+0

我希望我的編輯幫助。 – chmeee 2012-08-10 14:49:14