Class: Rdio::DesktopBridge

Inherits:
Object
  • Object
show all
Defined in:
lib/rdio/desktop_bridge.rb

Instance Method Summary collapse

Instance Method Details

#app_nameObject



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_albumObject



50
51
52
# File 'lib/rdio/desktop_bridge.rb', line 50

def current_album
  tell_rdio('album of the current track').chomp
end

#current_artistObject



46
47
48
# File 'lib/rdio/desktop_bridge.rb', line 46

def current_artist
  tell_rdio('artist of the current track').chomp
end

#current_trackObject



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_trackObject



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 now_playing(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

#pauseObject



26
27
28
# File 'lib/rdio/desktop_bridge.rb', line 26

def pause
  tell_rdio "pause"
end

#playObject



22
23
24
# File 'lib/rdio/desktop_bridge.rb', line 22

def play
  tell_rdio "play"
end

#previous_trackObject



38
39
40
# File 'lib/rdio/desktop_bridge.rb', line 38

def previous_track
  tell_rdio "previous track"
end

#quitObject



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

#toggleObject



30
31
32
# File 'lib/rdio/desktop_bridge.rb', line 30

def toggle
  tell_rdio "playpause"
end