Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add movie to iTunes using Scripting Bridge

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?

All I got is

iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier: @"com.apple.iTunes"];

Which is, as you can see, not much at all.

like image 643
Jeroen Avatar asked May 11 '10 18:05

Jeroen


1 Answers

Step 1. Generate iTunes.h header file:

sdef /Applications/iTunes.app | sdp -fh --basename "iTunes"

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);
like image 180
adib Avatar answered Oct 08 '22 04:10

adib