AppleScript的,POSIX文件名和美洲狮(Applescript, POSIX filen

2019-09-21 03:08发布

当我使用雪豹,我创建我的AppleScript时,多次使用以下模式:

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

任何人都可以启发对错误的含义是什么?

Answer 1:

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

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

因此,它的抱怨,路径是相对的,不是绝对的。 此警告不上来的狮子。



Answer 2:

一个简单的解决将是前缀路径file:/// 。 山狮预计,一切的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



文章来源: Applescript, POSIX filenames and Mountain Lion