Make a shortcut with the name: Get the Artist and Track Name
Inside this shortcuts you will use:
- Shazam it
- Copy Shazam Media to clipboard (action)
Save it…
Next play a song from any media.
Run this script and you will return the Artist and Track Name of the song.
tell application "Shortcuts Events"
run shortcut "Get the Artist and Track Name"
return (the clipboard) as text
end tell
Or if we like to use record instead.
set shazam to getArtistAndTrackCurrentPlaying()
log artist of shazam
log track of shazam
on getArtistAndTrackCurrentPlaying()
tell application "Shortcuts Events"
run shortcut "Get the Artist and Track Name"
end tell
set artistTrack to (the clipboard) as text
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" - "}
set theList to every text item of artistTrack
set AppleScript's text item delimiters to ASTID
return {artist:item 1 of theList, track:item 2 of theList}
end getArtistAndTrackCurrentPlaying
1 Like
So could we make something more useful and automate a script to change artist - track
from audio files. This simple example after trying to use and old script ASObjC that didn’t
work for me. Google made it not simple becouse playing a file and use ASObjC should work.
So I used afplay instead. I couldn’t use do shell script becouse I need 2 action to happen…
- Play the song.
- Run the shortcuts action.
Some ideas to a better solution is always welcome.
The script ask for audio file… play 10s and if shazam find the artist and track.
It will rename it with application “Finder”.
This version only accept 1 selection and quit after 10s
set theFile to POSIX path of (choose file)
tell application "Terminal" to do script "afplay -t 10 " & quoted form of theFile
set shazam to getArtistAndTrackCurrentPlaying()
delay 10
set target to POSIX file theFile as alias
set theFile to target
tell application "Finder"
set name of theFile to (artist of shazam) & "-" & (track of shazam)
end tell
on getArtistAndTrackCurrentPlaying()
tell application "Shortcuts Events"
run shortcut "Get the Artist and Track Name"
end tell
set artistTrack to (the clipboard) as text
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" - "}
set theList to every text item of artistTrack
set AppleScript's text item delimiters to ASTID
return {artist:item 1 of theList, track:item 2 of theList} as record
end getArtistAndTrackCurrentPlaying
1 Like