0

I'd like an easy way to switch from a Spotify release to the same release in Apple Music.

I already found a way to search for the currently playing Spotify track in the Apple Music web player with Applescript:

tell application "Spotify" if player state is not stopped then set currentArtist to artist of current track as string set currentTrack to name of current track as string open location "https://music.apple.com/search?term=" & currentArtist & " " & currentTrack end if end tell 

I'd love to:

  • Open the search in the native Music.app, not the web player. Is this supported?
  • Ideally not do a search, but go straight to the same release. Maybe with ISRC codes?
  • Take any selected Spotify track, not just the currently playing one. Looking at the Spotify Applescript dictionary tells me this in not possible.

2 Answers 2

1

had a similar problem right now and quickly hacked it out. In my case I want to simply trigger a search on the Music app.

Opened Automator and created a new "Service".

Workflow receives current > "Text" > in "every application".

Here's the AppleScript:

on run {input, parameters} tell application "Music" activate end tell tell application "System Events" tell process "Music" set window_name to name of front window set value of text field 1 of UI element 1 of row 1 of outline 1 of splitter group 1 of window window_name to input keystroke "" key code 36 end tell end tell return input end run 

I saved it as "Find on Music" in Automator and now I can select text, right click > Service > Find on Music and Music plops open and shows me the results for the selected text. I hope you can use some parts of it.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. Tried your script and I run into an "error number -1719" for some reason – I know too little about AppleScript to understand what's going wrong. However, I recently tried the Keysmith app, and I got it to work pretty easily by first running the AppleScript to copy the artist and track to the clipboard, and then using the Keysmith logic to paste the clipboard into the search field. Works perfect.
Do you have the newest Music and macOS version? Maybe the field order changed and broke something. But great that you found another solution :)
this no longer works, but it helped me figure out a solution that does (see other answer for fix)
0

I just figured out how to pass text from wherever to the search field in Music, with help from daemon's answer, which no longer works. This should work for what you want to do in conjunction with what you have.

Replace your "open location" line with a variable name for your concatenated string. Add this code below yours and pass that variable in place of 'input' (in my case 'input' is text from any application, which I use to select text of an artist name in an email/webpage/message that I want to send to Music's search).

First it checks to see if the main Music window is open vs the MiniPlayer, and open it if not to enable search via cmd-O, the cmd-F to find, then passes the input and hits return:

tell application "Music" activate end tell tell application "System Events" if not (exists (window "Music" of process "Music")) then tell process "Music" keystroke "0" using command down end tell end if tell process "Music" keystroke "f" using command down keystroke input key code 36 end tell end tell 

So, something like this (I don't have Spotify to check that section, but this should work assuming your code there is correct):

tell application "Spotify" if player state is not stopped then set currentArtist to artist of current track as string set currentTrack to name of current track as string set spotTrack to currentArtist & " " & currentTrack end if end tell tell application "Music" activate end tell tell application "System Events" if not (exists (window "Music" of process "Music")) then tell process "Music" keystroke "0" using command down end tell end if tell process "Music" keystroke "f" using command down keystroke spotTrack key code 36 end tell end tell 

The only thing I couldn't figure out is how to check if the search field is already in focus, because if it is, the cmd-F causes a system alert sound. Generally not an issue as typically you'll search and interact with something else before running this script again, so calling it good. :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.