thingsThingy code

// AppDelegate.swift
// thingsThingy
//
// Created by Paul Vallance on 15/03/2017.
// Copyright © 2017 Paul Vallance. All rights reserved.
//

import Cocoa
import Foundation

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

@IBOutlet weak var window: NSWindow!

let statusItem = NSStatusBar.system().statusItem(withLength: -2)

var myWindowController: NSWindowController!

func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application

if let button = statusItem.button {
button.image = NSImage(named: “StatusBarButtonImage”)
}

let menu = NSMenu()

menu.addItem(NSMenuItem(title: “New Thing”, action: #selector(AppDelegate.newThing(sender:)), keyEquivalent: “T”))
menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem(title: “About”, action: #selector(AppDelegate.windowAbout(sender:)), keyEquivalent: “A”))
menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem(title: “Quit thingsThingy”, action: #selector(AppDelegate.quit(sender:)), keyEquivalent: “q”))

statusItem.menu = menu
}

//applescript to launch Things Quick Entry Panel

func newThing(sender: NSMenuItem) {
let appleScript = NSAppleScript(source: “tell app \”Things\” to show quick entry panel”)

var possibleError: NSDictionary?
appleScript?.executeAndReturnError(&possibleError)

if let error = possibleError {
print(“ERROR: \(error)”)

}
}

//About Dialog box –

func windowAbout(sender: NSMenuItem){

let mainStoryboard = NSStoryboard.init(name: “Main”, bundle: nil)
myWindowController = mainStoryboard.instantiateController(withIdentifier: “aboutWindowController”) as!
NSWindowController
myWindowController.showWindow(self)
}

func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}

func quit(sender: NSMenuItem) {
NSApp.terminate(self)
}

}

//
// ViewController.swift
// thingsThingy
//
// Created by Paul Vallance on 15/03/2017.
// Copyright © 2017 Paul Vallance. All rights reserved.
//

import Cocoa
import Foundation

class ViewController: NSViewController {

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

override var representedObject: Any? {
didSet {
// Update the view, if already loaded.

}
}

}

// MARK: Actions

extension ViewController {

@IBAction func closeButton(_ sender: NSButton) {
print(“button clicked”)
view.window?.close()
// window!.close()
}

@IBAction func quitButton(_ sender: NSButton) {
NSApplication.shared().terminate(sender)
}
}