Trouble with AppleScript Permissions and ShazamKit Integration in macOS App

Hello fellow developers,

I am developing a macOS app called "Playlist Plunderer 2," aimed at using AppleScript to control the Music app to play songs and employing ShazamKit to recognize these songs and update their metadata. Despite setting up the entitlements and plist files correctly, I'm encountering issues with gaining the necessary AppleScript permissions, and my app is not appearing under 'Automation' in System Preferences. Additionally, ShazamKit fails to match songs, consistently returning error 201.

Here are the specifics of my setup and what I've tried so far:

Xcode Version: 15.4, macOS 14.1.2 Entitlements Configured: Includes permissions for Apple events, audio input, and scripting targets for the Music app. Capabilities: ShazamKit and ScriptingBridge frameworks integrated, set to "Do Not Embed." Info.plist Adjustments: Added "Privacy - Microphone Usage Description." Scripting: Manual AppleScript commands outside of Xcode succeed, but the app's scripts do not trigger. 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.automation.apple-events</key>
    <true/>
    <key>com.apple.security.device.audio-input</key>
    <true/>
    <key>com.apple.security.files.user-selected.read-only</key>
    <true/>
    <key>com.apple.security.scripting-targets</key>
    <dict>
        <key>com.apple.Music</key>
        <array>
            <string>com.apple.Music.playback</string>
            <string>com.apple.Music.library.read-write</string>
        </array>
    </dict>
</dict>
</plist>

I am having issues controlling the music app (itunes) from the apple script within my xcode project. the objective of the app is to rewrite the metadata of songs inside a folder in my Music app, this folder is titled Playlist Plunderer. The way I intend for the app to function is, the app will play the songs in the playlist, and then it will use shazamkit to recognize the song thats playing, it will then copy the metadata results of that song to rewrite the metadata of the song in the music playlist. I am still in the beginning stages. and I am very new to xcode. I created a apple developer account, paid the $99 and it is active, and I added the identifier bundle to the account from my app. I am VERY new to xcode,(this is my first project) my development team is set ( Shane Vincent), and the app is set to automatically manage signing, under app sandbox. i have audio input checked, under hardened runtime/ resource access audio input is checked. in build settings the path to the info.plist file is correct, the info.plist contains Privacy - Microphone Usage Description that I added i think it was called NSMmicriphone or something, with a description that reads "This app needs to access the microphone to identify songs using ShazamKit." the app appears under System Preferences > Security & Privacy > Privacy > Microphone but not under System Preferences > Security & Privacy > Privacy > Automation

it is being made on macOS 14.1.2 (23B92) and xcode Version 15.4 (15F31d)

Under framework library, and embedded content, I have added two frameworks, Shazamkit.framework, and ScriptingBridge.framework, both set to do not embed

Current Issue: AppleScript fails to authorize with the Music app, and ShazamKit errors suggest an issue with song matching.

Has anyone faced similar challenges or can offer guidance on how to ensure AppleScript and ShazamKit function correctly within a sandboxed macOS app? Any insights into troubleshooting or configuring entitlements more effectively would be greatly appreciated.

Thanks for your help!

I see two issues here:

  • Interacting with Music via Apple events.

  • ShazamKit not recognising songs.

I can help with the first but not the second (it’s way outside of my area of expertise). If, once we’re finished here, you are still having a problem with ShazamKit, I recommend that you start a new thread that focuses on that problem. Don’t mention AppleScript in that thread; it’s likely to frighten folks away (-:


Regarding your AppleScript issue, I have two points to start. First, are you targeting the Mac App Store? Or playing to distribute your app directly using Developer ID signing?

Second, are you able to write an AppleScript that returns the information you need from Music? If so, please post an example of that.

IMPORTANT When interacting with scriptable apps, it’s best to start with AppleScript. That is, after all, what the scripting interface was designed to support. Once you get that working, you can then make a decision as to whether to run the script from within your app, adopt a technology like ScriptingBridge, or send Apple events directly.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

thank you for your help, ok, I will focus simply on the Applescript. I am targeting the Mac App Store, I have been able to write an app in Python, that used applescript, and I was able to get it to do all of the commands my app required, open the Music app, Play songs from the specified Playlist, set specific playback points, cylce through the playlist, and then I had it scrape infromation from Shazams website, and then the AppleScript was able to replace the metadata it found from the website in the specified Playlist in Music. Without interacting with shazam I removed the second part of teh applescript that re writes the metadata to keep it simple, and this apple script Im providing is able to open the Music App. Cylce through the specified Playlist, & play each song at the specfied playback points.Im using script editor to run the script and it seems to work.


tell application "Music"

	set thePlaylist to playlist "Playlist Plunderer"

	if (count of tracks of thePlaylist) < 1 then

		display dialog "Playlist does not have any tracks."

		return

	end if

	

	repeat with theTrack in tracks of thePlaylist

		set trackDuration to duration of theTrack

		

		-- Play track at specified percentages

		repeat with p in {0.15, 0.5, 0.75}

			play theTrack

			delay 1

			set player position to trackDuration * p

			delay 4

			stop

		end repeat

	end repeat

end tell

I am targeting the Mac App Store

OK.

In that case I don’t think your approach is feasible. Mac App Store apps must be sandboxed, and the sandbox puts strict limits on the Apple events you send to other processes. It’s possible to disable those limits, using temporary exception entitlements, but my experience is that App Review generally rejects apps that try to do that [1].

IMPORTANT I don’t work for App Review and I can’t make definitive statements about their policy.

Given that, I can see potential paths forward:

  • You can continue down this path but choose to distribute your app directly, using Developer ID signing.

  • You can explore other ways to get this info. I’m not an expert on MusicKit by any means, but it does seem to offer some insight into playlists.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Although it’s a useful technique if you’re not shipping on the Mac App Store.

Trouble with AppleScript Permissions and ShazamKit Integration in macOS App
 
 
Q