Skip to content

Instantly share code, notes, and snippets.

@lackac
Created February 16, 2009 17:56
Show Gist options
  • Save lackac/65271 to your computer and use it in GitHub Desktop.
Save lackac/65271 to your computer and use it in GitHub Desktop.

Quacks

I created this simple script to play a random audio file from my ~/quacks directory. Then mapped this script to ⌃⌥Q with QuickSilver. This is like one free interaction just for me. I placed the default Adium sounds into this directory for a start.

The script creates a log from the numbers the audio files were played. If you don't need this just delete the file contents from line 9 to the end of file.

#!/usr/bin/env ruby
require 'yaml'
quacks = Dir[File.join(ENV['HOME'], 'quacks', '*.*')]
quack = quacks[rand(quacks.size)]
system %{afplay "#{quack}"}
quack = File.basename(quack)
stat_file = File.join(ENV['HOME'], 'quacks.log')
stats = YAML.load_file(stat_file) rescue {}
stats[quack] ||= 0
stats[quack] += 1
File.open(stat_file, "w") {|f| f.write(YAML.dump(stats))}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment