Question

I am using iTunes Scripting Bridge to search through the user's music in iTunes. Unfortunately, when I have App Sandbox enabled and use the following method from iTunes.h:

(iTunesTrack *) searchFor:(NSString *)for_ only:(iTunesESrA)only; 

It only returns nil. But if I disable App Sandboxing, it works perfectly fine. I can't seem to figure out what entitlements I need to include in my entitlement file to have this working correctly. Any ideas?

My code:

SBElementArray *iTunesSources = [self.iTunes sources];
iTunesSource *library;
for (iTunesSource *thisSource in iTunesSources) {
    if ([thisSource kind] == iTunesESrcLibrary) {
        library = thisSource;
        break;
    }
}
SBElementArray *libraryPlaylists = [library libraryPlaylists];
iTunesLibraryPlaylist *libraryPlaylist = [libraryPlaylists objectAtIndex:0];

SBElementArray* searchTracks = (SBElementArray *)[libraryPlaylist searchFor:searchTerm only:iTunesESrAAll];

My App.entitlements file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.app-sandbox</key>
    <true/>
    <key>com.apple.security.scripting-targets</key>
    <dict>
        <key>com.apple.iTunes</key>
        <array>
            <string>com.apple.iTunes.library.read-write</string>
            <string>com.apple.iTunes.playback</string>
            <string>com.apple.iTunes.playerInfo</string>
        </array>
    </dict>
</dict>

Was it helpful?

Solution

Look into Console and check what kind of sandbox violations are logged; then add the appropriate entitlements.

If it is "because it is not entitled to send an AppleEvent to this process." add this to the entitlement file:

<key>com.apple.security.temporary-exception.apple-events</key> <array> <key>com.apple.iTunes</key> </array>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top