Skip to content

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

@dstaley

Description

@dstaley

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions