Class: Player
- Inherits:
-
Object
- Object
- Player
- Defined in:
- lib/itc/player.rb
Instance Method Summary collapse
- #current_playlist_tracks ⇒ Object
- #current_track ⇒ Object
- #execute(script) ⇒ Object
- #next ⇒ Object
- #pause ⇒ Object
- #play(tracks) ⇒ Object
- #previous ⇒ Object
- #state ⇒ Object
Instance Method Details
#current_playlist_tracks ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/itc/player.rb', line 53 def current_playlist_tracks execute <<-SCRIPT tell application "iTunes" return database ID of tracks of current playlist end tell SCRIPT end |
#current_track ⇒ Object
49 50 51 |
# File 'lib/itc/player.rb', line 49 def current_track execute 'tell application "iTunes" to return database ID of current track' end |
#execute(script) ⇒ Object
4 5 6 |
# File 'lib/itc/player.rb', line 4 def execute(script) `osascript -e '#{script}'`.gsub(/\n$/, "") end |
#next ⇒ Object
37 38 39 |
# File 'lib/itc/player.rb', line 37 def next execute 'tell application "iTunes" to next track' end |
#pause ⇒ Object
33 34 35 |
# File 'lib/itc/player.rb', line 33 def pause execute 'tell application "iTunes" to pause' end |
#play(tracks) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/itc/player.rb', line 8 def play(tracks) if tracks.empty? execute 'tell application "iTunes" to play' else tracks = tracks.collect {|track| "database ID is #{track}"} execute <<-SCRIPT set pName to "itc" tell application "iTunes" if not ((name of playlists) contains pName) then set itcPlaylist to make new playlist with properties {name:pName} else set itcPlaylist to playlist pName delete every track of itcPlaylist end if duplicate (every track whose #{ tracks.join(" or ") }) to itcPlaylist play itcPlaylist end tell SCRIPT end end |
#previous ⇒ Object
41 42 43 |
# File 'lib/itc/player.rb', line 41 def previous execute 'tell application "iTunes" to previous track' end |
#state ⇒ Object
45 46 47 |
# File 'lib/itc/player.rb', line 45 def state execute 'tell application "iTunes" to return player state' end |