feat: add clipboard file handling for Mattermost and implement batch debounce functionality

This commit is contained in:
2026-05-15 07:54:01 -06:00
parent 7fc4320f46
commit 456a4c3381
5 changed files with 322 additions and 23 deletions

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env swift
import AppKit
import Foundation
let paths = CommandLine.arguments.dropFirst()
guard !paths.isEmpty else {
fputs("usage: copy_files_to_clipboard.swift <path> [path...]\n", stderr)
exit(64)
}
let urls = paths.map { URL(fileURLWithPath: $0).standardizedFileURL }
let missing = urls.filter { !FileManager.default.fileExists(atPath: $0.path) }
guard missing.isEmpty else {
for url in missing {
fputs("missing file: \(url.path)\n", stderr)
}
exit(66)
}
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
let wroteObjects = pasteboard.writeObjects(urls as [NSURL])
let filenamesType = NSPasteboard.PasteboardType("NSFilenamesPboardType")
let pathsList = urls.map(\.path)
let wroteFilenames = pasteboard.setPropertyList(pathsList, forType: filenamesType)
let wrotePlainText = pasteboard.setString(pathsList.joined(separator: "\n"), forType: .string)
if wroteObjects || wroteFilenames || wrotePlainText {
let itemCount = pasteboard.pasteboardItems?.count ?? 0
fputs("pasteboard files=\(urls.count) items=\(itemCount) objects=\(wroteObjects) filenames=\(wroteFilenames) text=\(wrotePlainText)\n", stderr)
exit(0)
}
fputs("failed to write file URLs to pasteboard\n", stderr)
exit(1)