3

在使用 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

任何人都可以启发错误的含义吗?

4

2 回答 2

5

这应该澄清问题和解决方案。所以首先解决问题

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 中。

于 2012-09-24T21:40:30.067 回答
0

一个简单的解决方法是在路径前加上file:///. Mountain Lion 需要所有内容的 URL,因此“裸”路径行不通。

例如,如果你想要/Users/RobertoAloi/file.txt you would pass infile:///Users/RobertoAloi/file.txt`。

CFURLGetFSRef 的详细信息可以在https://developer.apple.com/library/mac/#documentation/CoreFOundation/Reference/CFURLRef/Reference/reference.html找到

于 2012-08-10T13:22:59.607 回答