noahm Posted August 10, 2021 Share Posted August 10, 2021 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
jhncbrwn Posted August 12, 2021 Share Posted August 12, 2021 (edited) 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 August 12, 2021 by jhncbrwn noahm 1 Link to comment
noahm Posted August 13, 2021 Author Share Posted August 13, 2021 @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
deanishe Posted August 13, 2021 Share Posted August 13, 2021 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. noahm 1 Link to comment
noahm Posted August 13, 2021 Author Share Posted August 13, 2021 46 minutes ago, deanishe said: Letting Alfred put the query in the URL is smarter because Alfred will properly URL-encode it. I’m sorry, @deanishe, I’m not following on what to do... 🥴 Thanks for your patience. Link to comment
deanishe Posted August 13, 2021 Share Posted August 13, 2021 You put http://example.com?s={query} in the Open URL, and Alfred makes sure that the contents of {query} are properly URL-encoded. @jhncbrwn's script doesn't URL-encode the query, so the URL it creates will be invalid a lot of the time. noahm 1 Link to comment
noahm Posted August 13, 2021 Author Share Posted August 13, 2021 (edited) 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 August 13, 2021 by noahm Thought it was gonna render the markdown Link to comment
deanishe Posted August 13, 2021 Share Posted August 13, 2021 1 hour ago, noahm said: I actually using the `NSAppleScript` Right. Don't use that: it's a bit stupid. noahm 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now