使用Scripting Bridge将电影添加到iTunes [英] Add movie to iTunes using Scripting Bridge
问题描述
我想使用脚本桥将电影添加到iTunes.最好让我在音乐视频"和电影"之间进行选择.我知道Objective-C和AppleScript,所以我认为这并不难,但我无法弄清楚.我知道我将如何使用NSAppleScript,但是我的目标是10.5或更高版本,并且读到Scripting Bridge淘汰了NSAppleScript.是吗?
I want to use Scripting Bridge to add a movie to iTunes. And preferably letting me choose between a 'music video' and a 'movie'. I know both Objective-C and AppleScript so I thought it wouldn't be that hard but I can't figure it out. I know how I would use NSAppleScript for it but I'm targeting 10.5 or later and read that Scripting Bridge obsoletes NSAppleScript. Is that right?
我只有
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier: @"com.apple.iTunes"];
如您所见,这根本不多.
Which is, as you can see, not much at all.
推荐答案
步骤1.生成iTunes.h
头文件:
sdef /Applications/iTunes.app | sdp -fh --basename "iTunes"
第2步.添加媒体文件的代码如下:
Step 2. The code to add a media file looks like the following:
NSString* sourceMediaFile = ...;
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
iTunesTrack * track = [iTunes add:[NSArray arrayWithObject:[NSURL fileURLWithPath:sourceMediaFile]] to:nil];
NSLog(@"Added %@ to track: %@",sourceMediaFile,track);
这篇关于使用Scripting Bridge将电影添加到iTunes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!