Skip to content

Instantly share code, notes, and snippets.

@itarato
Created August 6, 2015 08:15
Show Gist options
  • Select an option

  • Save itarato/c8a7588c86b616c0adc5 to your computer and use it in GitHub Desktop.

Select an option

Save itarato/c8a7588c86b616c0adc5 to your computer and use it in GitHub Desktop.
Easy London time menu bar item for OS-X in Swift 2.
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var statusItem:NSStatusItem!
var timer:NSTimer!
func applicationDidFinishLaunching(aNotification: NSNotification) {
let statusBar = NSStatusBar.systemStatusBar()
self.statusItem = statusBar.statusItemWithLength(CGFloat(80.0))
self.updateLabel()
self.timer = NSTimer(timeInterval: NSTimeInterval(60), target: self, selector: Selector("updateTime:"), userInfo: self, repeats: true)
NSRunLoop.currentRunLoop().addTimer(self.timer, forMode: NSDefaultRunLoopMode)
}
func updateTime(t: NSTimer) {
self.updateLabel()
}
func updateLabel() {
let time = NSDate()
let formatter = NSDateFormatter()
formatter.timeZone = NSTimeZone(forSecondsFromGMT: 3600)
formatter.dateStyle = NSDateFormatterStyle.NoStyle
formatter.timeStyle = NSDateFormatterStyle.ShortStyle
self.statusItem.title = "LDN " + formatter.stringFromDate(time)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment