public
Description: my random ruby scripts
Homepage:
Clone URL: git://github.com/kastner/ruby-junk.git
Click here to lend your support to: ruby-junk and make a donation at www.pledgie.com !
ruby-junk / tunes_list.rb
100644 47 lines (40 sloc) 0.861 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def run_osa(script)
  result = ""
  IO.popen "osascript", "r+" do |io|
    io.write script
    io.close_write
    result = io.read.chomp
  end
  return result
end
 
def run_osa_itunes(script)
  run_osa <<-OSA
tell application "iTunes"
#{script}
end tell
OSA
end
 
def run_osa_current(script)
  run_osa_itunes <<-OSA
tell current playlist
#{script}
end tell
OSA
end
 
def current_tracks
  tracks = run_osa_current("tracks")
  tracks.split(",").collect {|t| t.gsub(/^.*\s(\d+)$/, '\1') }
end
 
def current_track_id
  run_osa_itunes "get id of current track"
end
 
def track_name_in_current(track_id)
  run_osa_current "get name of track id #{track_id}"
end
 
track = current_track_id
tracks = current_tracks
 
if tracks.include?(track)
  tracks[tracks.index(track),10].each do |track_id|
    puts track_name_in_current(track_id)
  end
end