Cocoa SBridge:如何获取applescript的返回值(复杂类型)
一个月以来,我一直在尝试创建一个应用程序,该应用程序可以检测 iTunes 的当前曲目来标记歌曲并计算 bpm(通过录音按钮)。
当用户修改标签的某个字段时,曲目将被锁定在application :这意味着:如果 iTunes currentTrack 更改,我的应用程序将保留在上一个曲目上。
我的问题:我已经获得了上一首曲目的持久 ID。我创建了一个 applescript 来获取与此持久 ID 相对应的曲目。但我没有找到如何在应用程序的可可部分中获取此曲目!!!!
这里是脚本:
on open param
tell application "iTunes"
set trackItems to (every track of playlist "Library" whose persistent ID is param)
repeat with aTrack in trackItems
return aTrack
end repeat
return null
end tell
end open
在可可方面,
NSAppleEventDescriptor *desc = [findTrackWithPersistentIDScript runWithParameters: [NSArray arrayWithObjects: lockPersistentID ,nil]];
我可以用 NSAppleEventDescriptor 做什么?我想要一个 iTunesTrack 或 iTunesFileTrack 。我通过显示对话框确认该曲目已找到,
感谢您的阅读和帮助!
PS:当我调试时,如果我执行[ desc data ],我有一个 NSContreteData 和一个 iTunesItem。但我不知道如何获取这个 iTunesItem (我尝试了演员表...)并且我设法获取了它,我可以用它做什么来拥有 iTunesTrack 。
I'm trying since one month to create an application that detects the current track of iTunes to tag the song and calculate the bpm (through a taping button)
When the user modifies one of the field of the tag, the track is locked in the application : that means : if iTunes currentTrack changes, my application stay on the previous track.
My problem : I've got the persistent ID of the previous track. I created an applescript to get the track corresponding to this persistent ID. But I don't find how to get this track in cocoa part of the application !!!!
here the script :
on open param
tell application "iTunes"
set trackItems to (every track of playlist "Library" whose persistent ID is param)
repeat with aTrack in trackItems
return aTrack
end repeat
return null
end tell
end open
On cocoa side,
NSAppleEventDescriptor *desc = [findTrackWithPersistentIDScript runWithParameters: [NSArray arrayWithObjects: lockPersistentID ,nil]];
what can i do with the NSAppleEventDescriptor ? I would like to have a iTunesTrack or iTunesFileTrack . I verify with a display dialog that the track is well found
Thanks for reading and for your help !
PS : when i debug, if i do [ desc data ] , i have a NSContreteData and below an iTunesItem. But I don't know how to get this iTunesItem (i tried a cast...) and i managed to get it, what can i do with it to have an iTunesTrack .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 applescript 和 obj-c 之间来回转换字符串很容易。所以我的建议是只来回传递字符串。例如,您实际上无法对可可中的“轨道”执行任何操作,因此不要将其传回,因为您实际上并不需要它。而是传回曲目名称。或者将持久 ID 作为文本传回。或者传回“true”表示您找到了它,或者传回“false”表示您找不到它。
然后在cocoa中获取applescript结果的NSString只需使用[result stringValue]。
It's easy to convert strings back and forth between applescript and obj-c. So my sugestion would be to pass only strings back and forth. For example, you can't really do anything with "the track" in cocoa, so don't pass that back because you don't really need it anyway. Pass back the track name instead. Or pass back the persistent id as text. Or pass back "true" meaning you found it or "false" meaning you couldn't find it.
Then in cocoa to get the NSString of the applescript result just use [result stringValue].