Created
August 6, 2015 08:15
-
-
Save itarato/c8a7588c86b616c0adc5 to your computer and use it in GitHub Desktop.
Easy London time menu bar item for OS-X in Swift 2.
This file contains hidden or 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
| 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