Class: Rdio::DesktopBridge
- Inherits:
-
Object
- Object
- Rdio::DesktopBridge
- Defined in:
- lib/rdio/desktop_bridge.rb
Instance Method Summary collapse
- #app_name ⇒ Object
- #apple_script(cmd) ⇒ Object
- #current_album ⇒ Object
- #current_artist ⇒ Object
- #current_track ⇒ Object
- #current_url(protocol = 'http') ⇒ Object
- #next_track ⇒ Object
- #now_playing(text = nil) ⇒ Object
- #pause ⇒ Object
- #play ⇒ Object
- #previous_track ⇒ Object
- #quit ⇒ Object
- #set_volume(pct = 30) ⇒ Object
- #tell_rdio(cmd) ⇒ Object
- #toggle ⇒ Object
Instance Method Details
#app_name ⇒ Object
12 13 14 15 |
# File 'lib/rdio/desktop_bridge.rb', line 12 def app_name running_apps = apple_script 'tell application "System Events" to get the name of every process whose background only is false' running_apps.split(', ').grep(/Rdio/)[0].to_s.strip || 'Rdio' end |
#apple_script(cmd) ⇒ Object
4 5 6 |
# File 'lib/rdio/desktop_bridge.rb', line 4 def apple_script(cmd) `osascript -e '#{cmd}'` end |
#current_album ⇒ Object
50 51 52 |
# File 'lib/rdio/desktop_bridge.rb', line 50 def current_album tell_rdio('album of the current track').chomp end |
#current_artist ⇒ Object
46 47 48 |
# File 'lib/rdio/desktop_bridge.rb', line 46 def current_artist tell_rdio('artist of the current track').chomp end |
#current_track ⇒ Object
42 43 44 |
# File 'lib/rdio/desktop_bridge.rb', line 42 def current_track tell_rdio('name of the current track').chomp end |
#current_url(protocol = 'http') ⇒ Object
69 70 71 72 73 |
# File 'lib/rdio/desktop_bridge.rb', line 69 def current_url(protocol = 'http') path = tell_rdio('rdio url of the current track').chomp path.empty? ? nil : "#{protocol}://www.rdio.com#{path}" end |
#next_track ⇒ Object
34 35 36 |
# File 'lib/rdio/desktop_bridge.rb', line 34 def next_track tell_rdio "next track" end |
#now_playing(text = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rdio/desktop_bridge.rb', line 54 def (text=nil) return "Nothing playing" if current_track.empty? text ||= "Now playing: %{track} / %{artist} / %{album}" text % { :artist => current_artist, :track => current_track, :album => current_album } end |
#pause ⇒ Object
26 27 28 |
# File 'lib/rdio/desktop_bridge.rb', line 26 def pause tell_rdio "pause" end |
#play ⇒ Object
22 23 24 |
# File 'lib/rdio/desktop_bridge.rb', line 22 def play tell_rdio "play" end |
#previous_track ⇒ Object
38 39 40 |
# File 'lib/rdio/desktop_bridge.rb', line 38 def previous_track tell_rdio "previous track" end |
#quit ⇒ Object
17 18 19 20 |
# File 'lib/rdio/desktop_bridge.rb', line 17 def quit # apple_script "tell application \"Rdio\" to quit" tell_rdio "quit" end |
#set_volume(pct = 30) ⇒ Object
65 66 67 |
# File 'lib/rdio/desktop_bridge.rb', line 65 def set_volume(pct = 30) tell_rdio "set the sound volume to #{pct}" end |
#tell_rdio(cmd) ⇒ Object
8 9 10 |
# File 'lib/rdio/desktop_bridge.rb', line 8 def tell_rdio(cmd) apple_script "tell app \"#{app_name}\" to #{cmd}" end |
#toggle ⇒ Object
30 31 32 |
# File 'lib/rdio/desktop_bridge.rb', line 30 def toggle tell_rdio "playpause" end |