Add movie to iTunes using script bridge

I want to use Scripting Bridge to add a movie to iTunes. And it’s advisable to let me choose between “music video” and “movie”. I know both Objective-C and AppleScript, so I thought it would not be so difficult, but I cannot figure it out. I know how to use NSAppleScript for it, but I am targeting 10.5 or later and read that Scripting Bridge is deprecating NSAppleScript. Is it correct?

All I have is

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

Which, as you see, is not so much.

+7
objective-c itunes scripting-bridge
source share
3 answers

Step 1. Create the iTunes.h header file:

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

Step 2. The code to add the media file is as follows:

 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); 
+10
source share

To create a header file from a script description file ( .sdef ) from an iTunes file that you can get with the sdef program, you must use the scripting definition processor ( sdp ) program:

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

This will give you a file called iTunes.h . You then include this title in your project and look over it to find out what the iTunes scripting interface offers.

If it seems to you that you can’t do it using a script bridge (maybe not everything that can be done through the AppleScript interface can also be done using a script bridge), just go ahead and write AppleScript to do this, and then do this in your program using NSAppleScript .

+1
source share

For the second parameter, it takes a playlist object (or nil, as mentioned earlier). Once you have extracted an instance of the iTunesPlaylist * object using some means (several depending on your needs), you can pass it as a second parameter.

0
source share

All Articles