Created
July 11, 2021 10:57
-
-
Save kirillrogovoy/7cc71ed9dd8fdb76d9bc0b93b1566235 to your computer and use it in GitHub Desktop.
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 AppKit | |
let FILE_TARGET_DIR = NSString.path(withComponents: [NSHomeDirectory(), "gtd/files/"]) | |
let ns = NSPasteboard.general | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "yyyy_MM_dd_HH_mm_ss" | |
let fs = FileManager() | |
if let fileURLFromClipboard = ns.string(forType: NSPasteboard.PasteboardType.fileURL) { | |
var sourceFileURL = URL(string: fileURLFromClipboard)! | |
sourceFileURL.standardize() | |
let sourceFileName = sourceFileURL.lastPathComponent | |
let destFileName = dateFormatter.string(from: Date()) + "_" + sourceFileName | |
var destFileURL = URL(fileURLWithPath: NSString.path(withComponents: [FILE_TARGET_DIR, destFileName])) | |
destFileURL.standardize() | |
try! fs.copyItem(at: sourceFileURL, to: destFileURL) | |
print("[[file:\(destFileURL.path)][\(sourceFileName)]]") | |
exit(0) | |
} | |
if let screenshotData = ns.data(forType: NSPasteboard.PasteboardType.png) { | |
let destFileName = dateFormatter.string(from: Date()) + "_screenshot.png" | |
var destFileURL = URL(fileURLWithPath: NSString.path(withComponents: [FILE_TARGET_DIR, destFileName])) | |
destFileURL.standardize() | |
fs.createFile(atPath: destFileURL.path, contents: screenshotData) | |
print("[[file:\(destFileURL.path)][\(destFileName)]]") | |
exit(0) | |
} | |
let plainText = ns.string(forType: NSPasteboard.PasteboardType.string) | |
print(plainText ?? "") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment