Skip to content

Instantly share code, notes, and snippets.

@denisdefreyne
Last active August 29, 2015 13:55
Show Gist options
  • Save denisdefreyne/8749518 to your computer and use it in GitHub Desktop.
Save denisdefreyne/8749518 to your computer and use it in GitHub Desktop.

SAFAC (Simple Audio File Alarm Clock)

On friday, January 31st, I arrived in Brussels and accidentally locked myself out of my phone by entering three wrong PINs. Because I could not eject the SIM card to use my phone in a SIM-less mode, I could no longer set an alarm, and had to improvise.

I ended up writing this script to wake me up by playing specific audio files at a specific time.

#!/usr/bin/env ruby
require 'time'
def play
files = Dir['Music/iTunes/iTunes Media/Music/Air/Le Voyage Dans La Lune/*.m4a'].sort
files.each do |af|
res = system('afplay', af)
break if !res
end
end
def wait_for(time)
delay_in_s = (time - Time.now).to_i
h, m, s = delay_in_s/60/60, (delay_in_s/60 % 60), (delay_in_s % 60)
puts "Sleeping for #{delay_in_s} seconds (#{h}h #{m}min #{s}s)"
sleep(delay_in_s)
end
wait_for(Time.parse('9:00:00'))
play
@denisdefreyne
Copy link
Author

Missing a #sort on files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment