Skip to content

Instantly share code, notes, and snippets.

@perfaram
Last active December 24, 2015 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perfaram/6755536 to your computer and use it in GitHub Desktop.
Save perfaram/6755536 to your computer and use it in GitHub Desktop.
Function which listen for a Siri command, catch the name of the track, then play it in iTunes.Part of a Siriproxy Plugin. French speaking required.
listen_for /Mac play (.*)/i do |play|
#Only for french speaking !!!
replacements = [ ["My", "Me"], ["col", "Call"], ["radiant", "Radian"] ]
replacements.each {|replacement| play.gsub!(replacement[0], replacement[1])}
#Only for french speaking !!! [End]
itunescheck = system("osascript -e 'if application \"iTunes\" is running then return 1'");
if play==nil then
say "Viva la musica !", spoken: "Vivaa la mousiica !"
system("osascript -e 'tell application \"iTunes\" to play'");
puts '[Info - Plugin "Macintosh"] Telling iTunes to play'
request_completed
else
if itunescheck==true then
system("osascript -e 'tell application \"iTunes\" to play track \"#{play}\"'");
say "Vous écoutez : #{play}" #Currently listening at : {track name}
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
else
say "Je lance la musique…"
system("osascript -e 'tell application \"iTunes\" to play track \"#{play}\"'"); #Telling iTunes to play
sleep 2
# if itunesbugtest==1 then
# say "Il semblerait que le morceau que vous avez demandé n'existe pas."
# request_completed
# else
say "Vous écoutez : #{play}" #Currently listening at : {track name}
request_completed #always complete your request! Otherwise the phone will "spin" at the user!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment