• 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: Setting iTunes album art with ScriptingBridge
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting iTunes album art with ScriptingBridge


  • Subject: Re: Setting iTunes album art with ScriptingBridge
  • From: Daniel Thorpe <email@hidden>
  • Date: Thu, 22 May 2008 17:58:10 +0100

Hi everyone,

I'm trying to set the artwork of some iTunes tracks using Cocoa & Scripting Bridge. The artwork is being generated using Cocoa, and I planned to use the SB to set the NSImage to the iTunesTracks.

However after reading this thead, it seems that it isn't really feasable (if someone has managed to do it correctly - then that would be great!) So, it looks like I've got to use AppleScript... which I've never really had much luck with... So, I'm hoping someone can help me go from having an NSImage in an Objective-C class to calling this

set data of front artwork of someTrackReference to somePICTData

in AppleScript? I'm guessing I need to write some function in Applescript, and pass in references to the track and the image data. Ideally I'd like to not have to write the images to disk and then pass in a filepath. If anyone can tell me how to do this that would be great!


Cheers
Dan

On 27 Feb 2008, at 19:20, Bill Monk wrote:

On Feb 27, 2008, Dave Verwe wrote:

// Add to iTunes
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier: @"com.apple.iTunes"];
iTunesTrack *track = [iTunes add: [NSArray arrayWithObject: [NSURL fileURLWithPath: file]] to: nil];


// Convert to PICT
NSData *tiffData = [artwork TIFFRepresentation];
NSPasteboard *pboard = [NSPasteboard pasteboardWithName:@"Sample"];
[pboard declareTypes: [NSArray arrayWithObject: NSTIFFPboardType] owner: nil];
[pboard setData: tiffData forType: NSTIFFPboardType];
[pboard types];
NSData *pictData = [pboard dataForType: NSPICTPboardType];
[pboard releaseGlobally];


// Add the artwork to the track
iTunesArtwork *artwork = (iTunesArtwork *)[[SBObject alloc] initWithProperties: [NSDictionary dictionaryWithObjectsAndKeys: @"data", pictData, nil]];
[[track artworks] insertObject: artwork atIndex: 0];

I haven't delved deeply into Scripting Bridge, but based on something similar that occurs when Applescripting iTunes, I suspect the problem is in the line:


[[track artworks] insertObject: artwork atIndex: 0];

A track's "artworks" does not exist for tracks which do not already contain artwork. Further, if you try to access it (or "kind of front artwork"), certain versions of iTunes will return the classic "Apple event not handled" error -1708. Other versions will return 0, as one might expect.


In any case, your solution in SB likely involves avoiding "artworks" altogether. Basically you want to replicate the Applescript command

set data of front artwork of someTrackReference to somePICTData

Observe that "artworks" is not involved at all. It will only exist for the track after some artwork data has been added.


(PS. I think it's preferable to include small code snippets in list postings rather as links to some external "snippets" web page. For one thing, that page may not exist years from now. For another, people who could possibly help with your issue may not bother to click your link. I almost didn't.)
_______________________________________________


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

_______________________________________________

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: Setting iTunes album art with ScriptingBridge
      • From: "Kyle Sluder" <email@hidden>
  • Prev by Date: Re: Application rights.
  • Next by Date: Re: A directory site for open-source Cocoa components?
  • Previous by thread: Re: A directory site for open-source Cocoa components?
  • Next by thread: Re: Setting iTunes album art with ScriptingBridge
  • Index(es):
    • Date
    • Thread