Skip to content

Instantly share code, notes, and snippets.

@dmytro
Created November 20, 2012 01:56
Show Gist options
  • Save dmytro/4115472 to your computer and use it in GitHub Desktop.
Save dmytro/4115472 to your computer and use it in GitHub Desktop.
Low tech Mac music player
#!/usr/bin/env ruby
def play songs
song = songs[rand songs.length].strip
puts song
song.gsub!('`','\\\\`')
$pid = Process.spawn "afplay -v .2 \"#{song}\""
Process.wait $pid
sleep 1
end
Kernel.trap('INT') { Process.kill "INT", $pid }
Kernel.trap('TSTP') { puts "Exiting..."; exit }
file = File.expand_path( ARGV[0] || "~/music.list")
songs = File.readlines(file)
play songs while true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment