1

这个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

谢谢

4

2 回答 2

6

好的 - 我已经知道我应该做什么了。

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

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

结果...

file "Macintosh HD:Users"

感谢你的协助。

安德鲁

于 2013-03-08T17:27:24.930 回答
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"
于 2013-03-08T16:34:41.737 回答