Jump to content

Get now playing song and pass it to a URL


Recommended Posts

Hello!

 

Not too sure what I’m doing or how to “pass” a result through to a URL. I have the following code in AppleScript and it’s showing me the appropriate result

 

tell application "Music"
	return (get name of current track) & (" ") & (get artist of current track)
end tell

 

I now want to pass that (song name and artist name) into a search result I have e.g.

 

https://example.com/s=SongName%20ArtistName

 

 

Any help would be greatly appreciated. Thank you.

Link to comment

Is this helpful?

 

tell application "Music"
	set MySearchtext to (get name of current track) & (" ") & (get artist of current track)
end tell

set MyURL to "https://example.com/s=" & MySearchtext

--If you want to open it in safari
tell application "Safari"
	open location MyURL
end tell

--If you want to pass it on to a open url Alfred action
return MyURL

 

Edited by jhncbrwn
Link to comment

@jhncbrwn thanks for your help! 

 

Unfortunately it doesn’t seem to be working for me.

 

I have the following Workflow setup, and it’s only opening up Safari and doing nothing else ☹️ :

 

_____

 

 

1. Keyword (Inputs → Keyword)

 

 

2. Run NSAppleScript (Actions → Run NSAppleScript):

tell application "Music"
	set MySearchtext to (get name of current track) & (" ") & (get artist of current track)
end tell

set MyURL to "https://example.com/s=" & MySearchtext

return MyURL

 

3. Open URL (Actions → Open URL)

 

 

_____

 

Also worth mentioning I’d rather just have it pass the result to the next action (if possible) rather than opening the URL via the script (i.e. type keyword, get music, pass that result to a “Open URL” action with an already built “Custom Search”)

 

Thanks!

 

Link to comment
39 minutes ago, noahm said:

Also worth mentioning I’d rather just have it pass the result to the next action

 

tell application "Music" to return (get name of current track) & " " & (get artist of current track)

 

Letting Alfred put the query in the URL is smarter because Alfred will properly URL-encode it.

Link to comment

Thanks @deanishe and @jhncbrwn!

 

I was trying that, but I actually using the “NSAppleScript” action which was causing the issues. Changing to "Run Script" (Actions → Run Script) and using “osascript (AppleScript)” executes everything properly.

Edited by noahm
Thought it was gonna render the markdown
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...