iTunes Scripting Bridge 显示不起作用 [英] iTunes Scripting Bridge reveal does not work

查看:15
本文介绍了iTunes Scripting Bridge 显示不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码应显示 iTunes 中的某个曲目:

The following code should show a certain track in iTunes:

NSString* iTunesPath = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"com.apple.iTunes"];

iTunesApplication *iTunes = nil;
if ( iTunesPath ) {
 iTunes = [[SBApplication alloc] initWithURL:[NSURL fileURLWithPath:iTunesPath]];
 [iTunes setDelegate:self];
}

iTunesSource *librarySource = nil;
NSArray *sources = [iTunes sources];
for (iTunesSource *source in sources) {
 if ([source kind] == iTunesESrcLibrary) {
  librarySource = source;
  break;
 }
}
SBElementArray *libraryPlaylist = [librarySource libraryPlaylists];
iTunesLibraryPlaylist *iTLibPlaylist = nil;
if ([libraryPlaylist count] > 0) {
 iTLibPlaylist = [libraryPlaylist objectAtIndex:0];
}


SBElementArray *fileTracks = [iTLibPlaylist fileTracks];

iTunesFileTrack *track = [fileTracks objectAtIndex:4];
NSLog(@"Try to reveal track: %@ at path :%@",[track description],[[track location] path]);
[track reveal];

输出:

Try to reveal track: <ITunesFileTrack @0x1364ed20: ITunesFileTrack 4 of ITunesLibraryPlaylist 0 of ITunesSource 0 of application "iTunes" (2474)> at path :/Users/...

但绝对注意到发生了.我究竟做错了什么?(iTunes 版本:9.0.3)

But absolutely noting happens. What am I doing wrong? (iTunes Version: 9.0.3)

推荐答案

库播放列表在 UI 中不再存在;它存在于模型中,因此它会出现在 AppleScript 中,但正如您所见,尝试显示它或其中的任何内容都不会在 UI 中执行任何操作.您也可以在 AppleScript 中重现此内容(显示源 1 的库播放列表 1 的曲目 5).

The Library playlist doesn't exist anymore in the UI; it's there in the model, so it shows up in AppleScript, but trying to reveal it or anything in it won't do anything in the UI, as you saw. You can reproduce this in AppleScript as well (reveal track 5 of library playlist 1 of source 1).

解决方案是与音乐播放列表对话,而不是与库播放列表对话.音乐"是第二个播放列表——playlist 2 在 AppleScript 中,[[librarySource playlists] objectAtIndex:1] 在 Cocoa 中.

The solution is to talk to the Music playlist, not the Library playlist. "Music" is the second playlist—playlist 2 in AppleScript, [[librarySource playlists] objectAtIndex:1] in Cocoa.

如果您想在正在播放的任何播放列表中显示正在播放的项目,请使用 reveal current track(应该是 [[iTunes currentTrack]reveal],虽然我还没有测试过).

If you want to reveal a playing item in whatever playlist it's playing in, use reveal current track (which should be [[iTunes currentTrack] reveal], although I haven't tested that).

这篇关于iTunes Scripting Bridge 显示不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆