As I understand, I need to use CommandGroup
in the App
struct to set up menu items in SwiftUI. So I have the following.
import SwiftUI
@main
struct Oh_My_App: App {
var body: some Scene {
WindowGroup {
ContentView(menuObservable: menuObservable)
}.commands {
CommandGroup(replacing: .newItem) {
}
CommandGroup(after: .newItem) {
Button {
} label: {
Text("Open...")
}
.keyboardShortcut("O")
}
}
}
}
If I launch the application, I find my Open command as shown in the screenshot below.
Well, my key equivalent is O. So the shortcut is supposed to be Command + O. But my Open command gets Command + Shift + O, which suggets that the O keyequivalent has been taken by something else. But by what!? There are only a dozen reserved commands as shown in the following screenshot. None of them uses O.
So my question is how can I assign Command + O to my Open command? Thanks.
If you use a lowercase "o"
, it will remove the Shift (which is a modifier that makes the "O"
uppercase):
.keyboardShortcut("o")