Skip to content

Instantly share code, notes, and snippets.

@rawnly
Created May 22, 2019 00:18
Show Gist options
  • Save rawnly/96ca5ca1eb0126179dc0c6789f134226 to your computer and use it in GitHub Desktop.
Save rawnly/96ca5ca1eb0126179dc0c6789f134226 to your computer and use it in GitHub Desktop.
//
// AppDelegate.swift
// Pasty
//
// Created by Federico Vitale on 22/05/2019.
// Copyright © 2019 Federico Vitale. All rights reserved.
//
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var timer: Timer!
let pasteboard: NSPasteboard = .general
var lastChangeCount: Int = 0
func applicationDidFinishLaunching(_ aNotification: Notification) {
timer = Timer.scheduledTimer(withTimeInterval: 0.05, repeats: true) { (t) in
if self.lastChangeCount != self.pasteboard.changeCount {
self.lastChangeCount = self.pasteboard.changeCount
NotificationCenter.default.post(name: .NSPasteboardDidChange, object: self.pasteboard)
}
}
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
timer.invalidate()
}
}
extension NSNotification.Name {
public static let NSPasteboardDidChange: NSNotification.Name = .init(rawValue: "pasteboardDidChangeNotification")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment