Menu

Your clipboard manager can see your passwords. What a Mac app should do about it
📰

Your clipboard manager can see your passwords. What a Mac app should do about it

DEV Community: swift·Mohammad Ali·about 17 hours ago
#WOkTLzzf
#devtoswift#devto#dev#clipboard#nspasteboard
Long article (868 words) — no AI summary yet.
Reading 0:00
15s threshold

Copy a password from your password manager, then open your clipboard history. If the password is sitting there in plain text, your clipboard tool is ignoring a convention that has existed on the Mac for years.

I build a clipboard manager, which means my app reads every single thing you copy. That's the whole feature. It's also why I spent more time on what it refuses to save than on what it saves. Below is how mine handles it, with the Swift code.

How a Mac app sees your clipboard

macOS has no "clipboard changed" notification. Every clipboard manager does the same thing: it polls NSPasteboard.general.changeCount on a timer and reads the pasteboard when the number goes up.

import AppKit

final class ClipboardWatcher { private var lastChange = NSPasteboard . general . changeCount private var timer : Timer ?

func start ( onChange : @escaping ( NSPasteboard ) -> Void ) { timer = Timer .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.