• 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
Re: 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]

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


  • Subject: Re: how can I pass file ref in objc scripting bridge (trying to add track to iTunes)
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Fri, 22 Feb 2008 23:52:05 +0100


Le 22 févr. 08 à 23:35, James Mead a écrit :

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];

Use NSURL. All file functions accept either NSURL or FSRef. As I don't know how to pass FSRef, so I'm using NSURL and it works.





_______________________________________________

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: "James Mead" <email@hidden>
References: 
 >how can I pass file ref in objc scripting bridge (trying to add track to iTunes) (From: "James Mead" <email@hidden>)

  • Prev by Date: how can I pass file ref in objc scripting bridge (trying to add track to iTunes)
  • Next by Date: Re: controllers, delegates, retain, release ...
  • Previous by thread: how can I pass file ref in objc scripting bridge (trying to add track to iTunes)
  • Next by thread: Re: how can I pass file ref in objc scripting bridge (trying to add track to iTunes)
  • Index(es):
    • Date
    • Thread