Created
January 14, 2012 20:12
-
-
Save meesterdude/1612721 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env macruby | |
framework 'Cocoa' | |
# Cocoa documentation reference: | |
# http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSSound_Class/Reference/Reference.html | |
def play_sound | |
if @sound.empty? | |
NSApplication.sharedApplication.terminate(nil) | |
else | |
sound_file = @sound | |
s = NSSound.alloc.initWithContentsOfFile(sound_file, byReference: false) | |
s.delegate = self | |
s.play | |
end | |
end | |
# This is a delegate method called by the sound object | |
def sound(sound, didFinishPlaying: state) | |
play_sound if state | |
end | |
# Delegate method called when the app finished loading | |
def applicationDidFinishLaunching(notification) | |
@sound = "/Users/ruru32/Desktop/SPOOL/TicTac.wav" | |
# STDOUT.sync = true #makes print flush | |
now = Time.new | |
twentyfive = now + 1*20 | |
puts "pomodoro ends #{twentyfive}" | |
while now < twentyfive do | |
sleep 2 | |
now = Time.new | |
print "." | |
play_sound | |
end | |
end | |
# We are delegating the application to self so the script will know when | |
# it finished loading | |
NSApplication.sharedApplication.delegate = self | |
NSApplication.sharedApplication.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment