Class: Player

Inherits:
Object
  • Object
show all
Defined in:
lib/itc/player.rb

Instance Method Summary collapse

Instance Method Details

#current_playlist_tracksObject



53
54
55
56
57
58
59
# File 'lib/itc/player.rb', line 53

def current_playlist_tracks
    execute "        tell application \"iTunes\"\n            return database ID of tracks of current playlist\n        end tell\n    SCRIPT\nend\n"

#current_trackObject



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

#nextObject



37
38
39
# File 'lib/itc/player.rb', line 37

def next
    execute 'tell application "iTunes" to next track'
end

#pauseObject



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 "            set pName to \"itc\"\n            tell application \"iTunes\"\n                if not ((name of playlists) contains pName) then\n                    set itcPlaylist to make new playlist with properties {name:pName}\n                else\n                    set itcPlaylist to playlist pName\n                    delete every track of itcPlaylist\n                end if\n\n                duplicate (every track whose \#{\n                    tracks.join(\" or \")\n                }) to itcPlaylist\n\n                play itcPlaylist\n            end tell\n        SCRIPT\n    end\nend\n"

#previousObject



41
42
43
# File 'lib/itc/player.rb', line 41

def previous
    execute 'tell application "iTunes" to previous track'
end

#stateObject



45
46
47
# File 'lib/itc/player.rb', line 45

def state
    execute 'tell application "iTunes" to return player state'
end