Skip to content

Instantly share code, notes, and snippets.

@meesterdude
Created January 14, 2012 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meesterdude/1612721 to your computer and use it in GitHub Desktop.
Save meesterdude/1612721 to your computer and use it in GitHub Desktop.
#!/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