Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iTunesArtwork.setData fails with error "object has not been added to a container yet; selector not recognized" #15

Open
dstaley opened this issue Feb 27, 2018 · 2 comments

Comments

@dstaley
Copy link

dstaley commented Feb 27, 2018

Hello!

First off, thank you for creating SwiftScripting! I've been banging my head against a wall trying to find a reasonable way to script my iTunes library, so I'm incredibly thankful for the work you've put into this.

I'm reasonably new to Scripting Bridge, so I'm not sure if this issue is with SB or with SwiftScripting or with my application code.

Basically, I'm trying to add album art to tracks in iTunes.

My script is (essentially) this:

let app = application(name: "iTunes") as! iTunesApplication

let sources = app.sources!() as! [iTunesSource]
let librarySource = sources.first!
let libraryPlaylists = librarySource.libraryPlaylists!() as! [iTunesLibraryPlaylist]
let library = libraryPlaylists.first!

let file = NSURL.fileURL(withPath: "/Users/dylanstaley/Documents/1799.m4a")
let track = app.add!([file], to: library as! SBObject)

let image = NSImage.init(contentsOfFile: "/Users/dylanstaley/Downloads/merged.png")
let artwork = objectWithApplication(app, scriptingClass: iTunesScripting.artwork) as iTunesArtwork
track.artworks!().add(artwork)
artwork.setData!(image)

When I run this script, I get the following error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[SBProxyByClass setData:]: object has not been added to a container yet; selector not recognized [self = 0x1015b04e0]'

From what I understand, SB objects need to be immediately added to their container before you can set properties on them. However, as far as I know, I'm doing just that. I mimicked the exact same structure with adding a playlist and it worked correctly, so I'm fairly sure I'm invoking it in the right way.

@tingraldi
Copy link
Owner

This one has me a bit stumped. I haven't reached a solution yet. Stay tuned...

@tingraldi
Copy link
Owner

Hmm...

It looks like setting iTunes track artwork is something like the "third rail" of the Scripting Bridge. There's an old thread on CocoaBuilder that basically concludes that you must resort to AppleScript for this task. See http://www.cocoabuilder.com/archive/cocoa/199978-setting-itunes-album-art-with-scriptingbridge.html#200000.

I'm close to officially giving up on this one, but I'll probably poke at it a bit more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants