From 6d8ae3fe8284f0667e9ff9d7cf401ca3c3a8fb76 Mon Sep 17 00:00:00 2001 From: remixz Date: Sun, 4 May 2014 19:35:06 -0700 Subject: [PATCH] Add "whats playing" command to Betty --- lib/itunes.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/itunes.rb b/lib/itunes.rb index 52d4e09..ad9a2fe 100755 --- a/lib/itunes.rb +++ b/lib/itunes.rb @@ -76,6 +76,19 @@ def self.prev(command) nil end end + + def self.playing(command) + matching = command.match(/^what\'?s?\s+((songs?|musics?|tracks?|iTunes)\s+)?(is)?\s?+play(?:ing)?$/i) + + if matching + { + :command => "osascript -e 'tell application \"iTunes\" to get name of current track'", + :explanation => "Gets the name of the playing track on iTunes." + } + else + nil + end + end def self.interpret(command) responses = [] @@ -98,6 +111,9 @@ def self.interpret(command) prev_command = self.prev(command) responses << prev_command if prev_command + playing_command = self.playing(command) + responses << playing_command if playing_command + responses end end