【问题标题】:Get current track file location on iTunes在 iTunes 上获取当前曲目文件位置
【发布时间】:2011-11-24 08:46:34
【问题描述】:

我试图用这个脚本从当前的 iTunes 曲目中检索文件位置:

on open info
    tell application "iTunes"
        set songLocation to get location of current track
    end tell
    return songLocation
end open

然后是代码:

desc = [_getFileLocScript runScript:someScript];
result = [desc stringValue];
NSLog (@"%@", result); //it shows null value.
NSLog (@"%@", desc); //it shows some numbers and key "alis".

输出:

<NSAppleEventDescriptor: 'alis'($000000000232000200000A4C656F7......FFFF0000$)>

问题是,该文件位置信息从 iTunes 的 applescript 实际返回的内容是什么?

【问题讨论】:

    标签: macos applescript


    【解决方案1】:

    Applescript 样式的路径与您可能习惯的路径有些不同。因此,对您来说最简单的事情就是找到您喜欢的风格的路径。因此,在您的 applescript 代码中,我会将您的代码行更改为此以获得斜线分隔的字符串,例如 /Users/username/Desktop/somefile.txt

    return posix path of songLocation
    

    然后一旦你在 cocoa 中有返回值,你可以看到 desc 是一个 NSAppleEventDescriptor。因此,如果您在文档中查找它,您会发现它没有“stringValue”方法,但是它确实有“string”方法,所以请使用它。因此,将您的行改为此...

    result = [desc string];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-08
      • 1970-01-01
      • 2016-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多