Applescript,POSIX文件名和Mountain Lion

时间:2012-08-10 13:19:35

标签: applescript posix

当我使用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 个答案:

答案 0 :(得分: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中没有出现此警告。

答案 1 :(得分:0)

一个简单的解决方法是使用file:///为路径添加前缀。 Mountain Lion需要所有内容的URL,因此“裸”路径不起作用。

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

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

找到CFURLGetFSRef的详细信息
相关问题