Support org.nspasteboard conventions for transient clipboard handlin

This commit is contained in:
Beingpax 2025-11-28 13:03:30 +05:45
parent e16c84e1ed
commit 1e612d9987
3 changed files with 20 additions and 11 deletions

View File

@ -1,5 +1,5 @@
{
"originHash" : "fa43afba90620dda26dfd9413de335295c333eb4c910af45f313d00c2a7decb3",
"originHash" : "144ae35ef0b62c92588dc767eb6b2d443797062688bf1347662bed55d75a7ec2",
"pins" : [
{
"identity" : "axswift",

View File

@ -6,13 +6,27 @@ struct ClipboardManager {
case copyFailed
case accessDenied
}
static func copyToClipboard(_ text: String) -> Bool {
static func setClipboard(_ text: String, transient: Bool = false) -> Bool {
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
return pasteboard.setString(text, forType: .string)
pasteboard.setString(text, forType: .string)
if let bundleIdentifier = Bundle.main.bundleIdentifier {
pasteboard.setString(bundleIdentifier, forType: NSPasteboard.PasteboardType("org.nspasteboard.source"))
}
if transient {
pasteboard.setData(Data(), forType: NSPasteboard.PasteboardType("org.nspasteboard.TransientType"))
}
return true
}
static func copyToClipboard(_ text: String) -> Bool {
return setClipboard(text, transient: false)
}
static func getClipboardContent() -> String? {
return NSPasteboard.general.string(forType: .string)
}

View File

@ -22,12 +22,7 @@ class CursorPaster {
}
}
pasteboard.clearContents()
pasteboard.setString(text, forType: .string)
if !preserveTranscript {
pasteboard.setData(Data(), forType: NSPasteboard.PasteboardType("org.nspasteboard.TransientType"))
}
ClipboardManager.setClipboard(text, transient: !preserveTranscript)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
if UserDefaults.standard.bool(forKey: "UseAppleScriptPaste") {