Skip to content

Instantly share code, notes, and snippets.

@luisgerhorst
Last active December 22, 2015 16:49
Show Gist options
  • Save luisgerhorst/6502192 to your computer and use it in GitHub Desktop.
Save luisgerhorst/6502192 to your computer and use it in GitHub Desktop.
Creating my first Mac app with MacRuby
#
# AppDelegate.rb
# Alarm
#
# Created by Luis Gerhorst on 09.09.13.
#
class AppDelegate
attr_accessor :window, :datePicker, :createAlarmButton, :deleteAlarmButton
def applicationDidFinishLaunching(a_notification)
datePicker.setDateValue(NSDate.date)
end
def createAlarm(sender)
puts "creating..."
@alarm = Alarm.new
@alarm.timer(datePicker.dateValue)
end
def deleteAlarm(sender)
puts "deleting..."
@alarm.delete
@alarm = nil
end
end
class Alarm
def timer(date)
@timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "fire:", userInfo: nil, repeats: true)
@timer.setFireDate(date)
puts "created"
end
def fire(userInfo)
NSSound.soundNamed('Basso').play
puts "fired"
end
def delete
@timer.invalidate
@timer = nil
puts "deleted"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment