POSIX文件错误 - 多余的双引号?

时间:2013-03-08 15:40:38

标签: macos applescript

这个AppleScript有效

set myFile to (POSIX path "/Users/fred/Documents/data.dat")

这个苹果不起作用

set myFileName to "/Users/fred/Documents/data.dat"
set myFile to (POSIX path myFileName)

失败并显示错误

    get POSIX file "/Users/fred/Documents/data.dat"
    --> error number -1728
Result:
error "iTunes got an error: Can’t get POSIX file \"/Users/fred/Documents/data.dat\"." number -1728 from file "Macintosh HD:Users:drew:Desktop:Music:DIY:DIY-01.mp3"

看起来好像在使用变量时,POSIX路径在文件名中包含双引号作为显式字符。我做错了什么?

下面的脚本再现了这个问题。

tell application "Finder"
    set newFileName to "/Users"
    set newFile to POSIX file newFileName
end tell

由于

2 个答案:

答案 0 :(得分:3)

好的 - 我发现了我应该做的事情。

以下脚本有效 - 您只需要强制变量而不是将其传递给POSIX file

tell application "Finder"
    set newFileName to "/Users"
    set newFile to (newFileName as POSIX file)
end tell

结果...

file "Macintosh HD:Users"

感谢您的协助。

安德鲁

答案 1 :(得分:1)

“/ Users / fred / Documents / data.dat”已经是posix路径

tell application "Finder" to open POSIX file "/Users/fred/Documents/data.dat"

tell application "System Events" to open "/Users/fred/Documents/data.dat"

以下是iTunes的示例:

tell application "Finder" to set myFile to (POSIX file "/Users/John/Desktop/08 5150.mp3")
tell application "iTunes" to set resultTrack to add myFile to playlist "test"