Created
May 22, 2019 00:18
-
-
Save rawnly/96ca5ca1eb0126179dc0c6789f134226 to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// 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