• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
how can I pass file ref in objc scripting bridge (trying to add track to iTunes)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how can I pass file ref in objc scripting bridge (trying to add track to iTunes)


  • Subject: how can I pass file ref in objc scripting bridge (trying to add track to iTunes)
  • From: "James Mead" <email@hidden>
  • Date: Fri, 22 Feb 2008 17:35:34 -0500

I'm trying to add an mp3 file to iTunes using the scripting bridge.
I'm successful at instantiating an iTunes object and talking to it (able to
retrieve playlist and track info), but I'm at a loss at to how to add a
track.

Code portions:

// find already running iTunes

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


// a test file to add (not shown - I used FSNewAliasFromPath and FSPathMakeRef
to verify the path name was valid and could be turned into a file reference)


NSString *aFilePath = @"//Users/jmead1/bach.mp3"; // test file


// to add a file to iTunes library, add it to the library playlist. Script
Editor shows the to: part as optional, but if I leave it out I get syntax
error.


// locate the iTunes library playlist

SBElementArray *sources = [iTunes sources];

iTunesSource *libsource=nil;

 uint i;

for (i=0; i<[sources count]; i++)

{

if ([[sources objectAtIndex:i] kind] == 'kLib')

{

libsource = [sources objectAtIndex:i];

break;

}

}


SBElementArray *libPlaylists = [[libsource libraryPlaylists] copy];

id anObject = [[libPlaylists objectAtIndex: 0] get];

iTunesLibraryPlaylist *theLibraryPlaylist = anObject;


// tried:
// 1. using just the filename string as the array object (gives same error
-35)
// 2. using aliasHandle from successful FSNewAliasFromPath call - this gives
syntax error in the array constructor
// 3. using FSRef from successful FSPathMakeRef call - this gives syntax
error in the array constructor
// 4. put the filename in quotes and prefixed with "alias " - gives same
error -35
// 5. this attempt -- put the file name in quotes and prefixed with "POSIX
file " - error -35 shown below.

NSMutableString *anotherFileName = [@"POSIX file \"" mutableCopy];

[anotherFileName appendString: aFilePath];

[anotherFileName appendString: @"\""];

 NSArray *anNSArrry = [NSArray arrayWithObject: anotherFileName];

 iTunesTrack *anITunesTrack = [iTunes add: anNSArrry to
: theLibraryPlaylist];



Error result from my latest attempt is:

*Error: NSGenericException, Apple event returned an error.  Event =
'hook'\'Add '{ '----':[ 'utxt'("POSIX file \"//Users/jmead1/bach.mp3\"") ],
'insh':'obj '{ 'want':'cLiP', 'from':'obj '{ 'want':'cSrc', 'from':'null'(),
'form':'ID  ', 'seld':42 }, 'form':'ID  ', 'seld':1472 } }*

*Error info = {*

*    ErrorNumber = -35;*

*}*

*
*

What kind of object do I need to use to create the file name array?

or am I completely misunderstanding how to do this?


Thanks

Jim
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: how can I pass file ref in objc scripting bridge (trying to add track to iTunes)
      • From: Jean-Daniel Dupas <email@hidden>
  • Prev by Date: Re: controllers, delegates, retain, release ...
  • Next by Date: Re: how can I pass file ref in objc scripting bridge (trying to add track to iTunes)
  • Previous by thread: Re: setting exif metadata with ApplicationServices framework
  • Next by thread: Re: how can I pass file ref in objc scripting bridge (trying to add track to iTunes)
  • Index(es):
    • Date
    • Thread