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

Permissions problem trying to talk to APple music #6

Closed
ijabz opened this issue Jun 7, 2022 · 14 comments
Closed

Permissions problem trying to talk to APple music #6

ijabz opened this issue Jun 7, 2022 · 14 comments
Assignees
Labels
question Further information is requested

Comments

@ijabz
Copy link

ijabz commented Jun 7, 2022

User using jaikoz getting

image

I have

<key>NSAppleEventsUsageDescription</key>
<string>Jaikoz uses AppleEvents to update your Music.app library</string>

in my Info.plist so I assume that is correct, but Im unclear how it works is a message meant to come up for user asking them for permission, and does it happen just the once.

@hendriks73
Copy link
Collaborator

The user was presented with a dialog from the system saying "Jaikoz uses AppleEvents to update your Music.app library", but probably didn't notice it or chose to ignore it.

Yes, as far as I know, it happens just once. I have no idea why Apple thought that's a good idea. 🤔

See also this rather old blog post: https://blog.beatunes.com/2018/10/beatunes-on-mojave-and-windows-10-dark.html (subheadline AEpocalypse :: Averted) The tool tccutil and the automation privacy settings may help your user.

@hendriks73 hendriks73 added the question Further information is requested label Jun 7, 2022
@hendriks73 hendriks73 self-assigned this Jun 7, 2022
@ijabz
Copy link
Author

ijabz commented Jun 13, 2022

Hi, okay I used tccutil reset AppleEvents on my Mac and and now I am having same error as user, when I start Jaikoz I dont see any request for permissions, I dont know if i have added the key to Info.plist the wrong way (its done via Appbundler), please see contents of Info.plist for Jaikoz below:

<?xml version="1.0" ?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>Jaikoz</string>
<key>CFBundleIconFile</key>
<string>jaikoz.icns</string>
<key>CFBundleIdentifier</key>
<string>com.jthink.jaikoz</string>
<key>CFBundleDisplayName</key>
<string>Jaikoz</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Jaikoz</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>11.5.1</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleHelpBookFolder</key>
<string>JaikozHelp</string>
<key>CFBundleHelpBookName</key>
<string>com.jthink.jaikoz.Help</string>
<key>CFBundleAllowMixedLocalizations</key>
<false/>
<key>CFBundleSignature</key>
<string>jaik</string>
<key>NSHumanReadableCopyright</key>
<string></string>
<key>LSMinimumSystemVersion</key>
<string>10.7</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.music</string>
<key>LSUIElement</key>
<false/>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
<key>IgnorePSN</key>
<false/>
<key>NSRequiresAquaSystemAppearance</key>
<false/>
<key>JVMRuntime</key>
<string>temurin-17.jdk</string>
<key>JREPreferred</key>
<false/>
<key>JDKPreferred</key>
<false/>
<key>JVMMainClassName</key>
<string>com.jthink.jaikoz.Jaikoz</string>
<key>JVMDebug</key>
<false/>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>jai</string>
</array>
<key>LSTypeIsPackage</key>
<false/>
<key>CFBundleTypeName</key>
<string>Jaikoz License</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>mp3</string>
<string>mp4</string>
<string>m4a</string>
<string>wma</string>
<string>ogg</string>
<string>flac</string>
</array>
<key>LSTypeIsPackage</key>
<false/>
<key>CFBundleTypeName</key>
<string>Music Files</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
</array>
<key>LSArchitecturePriority</key>
<array>
</array>
<key>LSEnvironment</key>
<dict>
<key>LC_CTYPE</key>
<string>UTF-8</string>
</dict>
<key>JVMOptions</key>
<array>
<string>-Dapple.laf.useScreenMenuBar=true</string>
<string>-Dapple.awt.brushMetalLook=true</string>
<string>-Dsun.java2d.metal=true</string>
<string>-Dapple.awt.application.appearance=system</string>
</array>
<key>JVMDefaultOptions</key>
<dict>
</dict>
<key>JVMArguments</key>
<array>
<string>-l</string>
<string>2</string>
<string>-m</string>
<string>2</string>
</array>
<key>NSAppleEventsUsageDescription</key>
<string>Jaikoz uses AppleEvents to update your Music.app library,</string>
</dict>
</plist>



@hendriks73
Copy link
Collaborator

As far as I can tell the Info.plist looks ok.

@ijabz
Copy link
Author

ijabz commented Jun 13, 2022

What displays the message, do I have to handle it in my code or is the message displayed independently to my application ?
Is there a Apple setting that I could have that prevents it being displayed
Fails for both Jaikoz and SongKong, I dont know know how I gave permission in first place it just worked when I started using your libs.

@hendriks73
Copy link
Collaborator

What displays the message

macOS.

Is there a Apple setting that I could have that prevents it being displayed

I believe, previously ignoring the dialog or answering the dialog prevents it from being displayed.

Is there anything in System Preferences -> Security& Privacy -> Privacy -> Automation? That's where the user can turn access on or off. In theory.

@ijabz
Copy link
Author

ijabz commented Jun 13, 2022

I believe, previously ignoring the dialog or answering the dialog prevents it from being displayed.

but that is reset if I have done tccutil reset AppleEvents ?

Nothing in Automation and tried it on two different macs with same results

@hendriks73
Copy link
Collaborator

Hm... Sorry, then I am out of ideas.

@ijabz
Copy link
Author

ijabz commented Jul 6, 2022

  • I ran tccutil reset AppleEvents again
  • I installed Beatunes and ran it, and selected Create Library from Music the message came up and I had no problems
  • I then copied the NSAppleEventsUsageDescription key and string from Beatunes Info.plist and put it directly under <dict> in SongKong Info.plist
  • I then ran SongKong again and got the error again, the error occurs when call getFileTracks() in code below
Application app = Application.getInstance();
Playlist globalPlaylist = app.getPlaylist(GLOBAL_PLAYLIST_INDEX);
FileTrack[] fileTracks  = globalPlaylist.cast(LibraryPlaylist.class).getFileTracks();
  • Wondering if the code that calls Music app or something has to be on Event Dispatch Thread or something, could you post the Beatunes code that triggers the message to be displayed first time round ?

@ijabz
Copy link
Author

ijabz commented Jul 13, 2022

If I run SongKong application from a shell script (that uses the default installed Java) then I get the authorisation message coming up for Terminal to give access to Music, and If i enable then the application works, and Terminal/Music shows up in Security/Privacy/Automation, but that isnt a viable solution for users.

So Im thinking there is something wrong with Info.plist, or maybe there is some issue that Im using a bundled jre (cut down using jlink) ?

@hendriks73
Copy link
Collaborator

Wondering if the code that calls Music app or something has to be on Event Dispatch Thread

All AppleScript has to be called on the macOS main thread. This is something that is taken care of by JaplScript.

could you post the Beatunes code that triggers the message to be displayed first time round ?

Not really.

So Im thinking there is something wrong with Info.plist, or maybe there is some issue that Im using a bundled jre (cut down using jlink) ?

I wish I could help, but am out of ideas. Yes, perhaps it has something to do with how you launch your app, but I don't know what it is. Sorry.

@ijabz
Copy link
Author

ijabz commented Jul 13, 2022

okay, I'll keep informed as I try things out.

Using appbundler from Infinitekind
Simpliifed build to just use the JRE installed on the Mac (which is temerin Jdk 17) , and still failed in same way.

@ijabz
Copy link
Author

ijabz commented Jul 13, 2022

Found the solution here https://ishaangandhi.medium.com/sending-applescript-events-from-electron-app-18dc1b7d7a51

Need to add


<key>com.apple.security.automation.apple-events</key>
<true/>

to my songkong.entitlements file, tried it and it work

@hendriks73
Copy link
Collaborator

Just checked, beaTunes has that key, too. But to be honest, I don't even remember adding it.

Thank you for sharing. I will add a note to somewhere to JaplScript, so that others don't fall into the same trap.

@hendriks73
Copy link
Collaborator

I have added appropriate remarks in the README.md in the JaplScript project (currently still in dev branch).

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

No branches or pull requests

2 participants