TRIGGERcmd
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Alexa report What Artist & What Song in Music

    Mac
    1
    2
    83
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      gajahduduk
      last edited by gajahduduk

      I wanted Alexa to be able to report what is playing in (Apple) Music. I came up with these, which I am delighted to say, work:

      WHAT ARTIST

      osascript -e 'tell application "music" to set result to artist of current track' | sed 's/^/"/;s/$/"/' | xargs -I{} ~/.TRIGGERcmdData/sendresult.sh {}
      

      Voice: what artist
      Voice Reply: This artist is {{result}}

      WHAT SONG

      osascript -e 'tell application "Music" to set result to "This song is " & name of current track & " by " & artist of current track & " on the " & year of current track & " album " & album of current track' | sed 's/^/"/;s/$/"/' | xargs -I{} ~/.TRIGGERcmdData/sendresult.sh {}
      

      Voice: what song
      voice reply: {{result}}

      Note: I'm not a terminal wiz, I'm not sure if this is the most efficient way to do this (happy for suggestions), but it works. the "sed" part is just to quote the result from "Music"

      Of course you have to enable the Trigger Command Alexa skill. So you'd say:

      "Alexa, ask Trigger Command to run What Song" or "…What Album"

      BONUS: NEXT ALBUM

      and now that I was on a roll, I tried something more complicated that needs to run an applescript file, playing a new album in the current playlist:

      osascript ~/Library/Scripts/Applications/Music/commands/next.album.scpt | sed 's/^/"/;s/$/"/' | xargs -I{} ~/.TRIGGERcmdData/sendresult.sh {}
      

      voice: Next Album
      voice reply: {{result}}

      applescript:

      tell application "Music"
      	set rcount to 0
      	set talb to album of current track
      	repeat
      		set rcount to rcount + 1
      		next track
      		set newalbum to album of current track
      		set newartist to artist of current track
      		if newalbum is not talb or rcount > 30 then exit repeat
      	end repeat
      	set result to "Playing " & newalbum & " by " & newartist
      end tell
      

      (saved as "next.album.scpt" and saved to path as given above. of course you can rename and/or change the path. the count is just a fail safe if album has too many tracks, can change of course)

      1 Reply Last reply Reply Quote 0
      • G
        gajahduduk
        last edited by

        IMPORTANT NOTE on above

        you must make the sendresult.sh bash script executable. go to terminal and:

        cd ~/.TRIGGERcmdData/
        chmod +x sendresult.sh
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post