Klaudiusz Dembler
Klaudiusz Dembler

Reputation: 91

How to enable pasting with keyboard shortcut into SwiftUI macOS agent application

I'm creating an app with Swift 5 and SwiftUI. The application runs as a status bar app (LSUIElement is true). I've created a simple preferences window with SwiftUI with a couple of TextField.

However, I don't know how I can enable pasting into those fields with Cmd+V. The app being an agent, it's never really activated so even with the preferences window focused, app's menu bar doesn't show up (on the left-hand side of the status bar).

This is how I create the window:

let hostingController = NSHostingController(rootView: PreferencesView())
preferencesWindow = NSWindow(contentViewController: hostingController)
preferencesWindow!.center()
preferencesWindow!.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)

When trying to paste using Cmd+V I hear the macOS's "forbidden" chime. Right-clicking the field allows me to select Paste from the popup menu.

Upvotes: 9

Views: 604

Answers (1)

Pudge Ma
Pudge Ma

Reputation: 11

I have the same trouble, then I find these shortcuts is provided by the 'Edit' menu item. so you can try restoring the default menu in Main.storyboard.

Upvotes: 1

Related Questions