Created
April 11, 2011 20:01
-
-
Save xoebus/914205 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flash_running? | |
begin | |
`ps aux`.split("\n").find { |process| process.include? "Flash" }.match(/\w+\s*\d+\s*([\d.]+)\s*.*/)[1].to_i > 4 | |
rescue NoMethodError | |
false | |
end | |
end | |
def sample | |
results = [] | |
5.times do | |
results << flash_running? | |
sleep 1 | |
end | |
if results.count(true) > 4 | |
puts "Flash is playing..." | |
true | |
else | |
puts "Flash is not playing..." | |
false | |
end | |
end | |
loop do | |
unless sample | |
puts "Playing if we aren't playing..." | |
`osascript -e "tell application \\"iTunes\\" to play"` | |
end | |
sleep 20 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment