Skip to content

Commit 425ddf7

Browse files
committed
Prevent Option key without Command or Control on macOS 15 or later in sandboxed apps
Fixes #176
1 parent 68d5d2d commit 425ddf7

File tree

22 files changed

+62
-3
lines changed

22 files changed

+62
-3
lines changed

Example/KeyboardShortcutsExample.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@
315315
ENABLE_HARDENED_RUNTIME = YES;
316316
ENABLE_PREVIEWS = YES;
317317
GENERATE_INFOPLIST_FILE = YES;
318+
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
318319
LD_RUNPATH_SEARCH_PATHS = (
319320
"$(inherited)",
320321
"@executable_path/../Frameworks",
@@ -343,6 +344,7 @@
343344
ENABLE_HARDENED_RUNTIME = YES;
344345
ENABLE_PREVIEWS = YES;
345346
GENERATE_INFOPLIST_FILE = YES;
347+
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
346348
LD_RUNPATH_SEARCH_PATHS = (
347349
"$(inherited)",
348350
"@executable_path/../Frameworks",

Example/KeyboardShortcutsExample/MainScreen.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ private struct DoubleShortcut: View {
106106
.frame(maxWidth: 300)
107107
.padding()
108108
.padding()
109-
.onKeyboardShortcut(.testShortcut1) {
109+
.onGlobalKeyboardShortcut(.testShortcut1) {
110110
isPressed1 = $0 == .keyDown
111111
}
112-
.onKeyboardShortcut(.testShortcut2, type: .keyDown) {
112+
.onGlobalKeyboardShortcut(.testShortcut2, type: .keyDown) {
113113
isPressed2 = true
114114
}
115115
.task {

Sources/KeyboardShortcuts/CarbonKeyboardShortcuts.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ enum CarbonKeyboardShortcuts {
147147
registerError == noErr,
148148
let carbonHotKey = eventHotKey
149149
else {
150+
print("Error registering hotkey \(shortcut):", registerError)
150151
return
151152
}
152153

@@ -181,6 +182,7 @@ enum CarbonKeyboardShortcuts {
181182
error == noErr,
182183
let eventHotKey
183184
else {
185+
print("Error registering hotkey \(hotKey.shortcut):", error)
184186
hotKeys.removeValue(forKey: hotKey.carbonHotKeyId)
185187
continue
186188
}

Sources/KeyboardShortcuts/Localization/ar.lproj/Localizable.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"keyboard_shortcut_used_by_menu_item" = "لا يمكن استخدام اختصار لوحة المفاتيح هذا لأنه مستخدم بواسطة عنصر القائمة “%@”.";
44
"keyboard_shortcut_used_by_system" = "لا يمكن استخدام اختصار لوحة المفاتيح هذا لأنه مستخدم مسبقاً على مستوى النظام.";
55
"keyboard_shortcuts_can_be_changed" = "يمكن تغيير معظم اختصارات لوحة المفاتيح على مستوى النظام في “تفضيلات النظام > لوحة المفاتيح > الاختصارات ”.";
6+
"keyboard_shortcut_disallowed" = "يجب دمج مفتاح Option مع Command أو Control.";
67
"ok" = "موافق";
78
"space_key" = "مسافة";

Sources/KeyboardShortcuts/Localization/cs.lproj/Localizable.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"keyboard_shortcut_used_by_menu_item" = "Tuto zkratku nelze použít, protože je již využívána položkou „%@“";
44
"keyboard_shortcut_used_by_system" = "Tuto zkratku nelze použít, protože už ji používá systém.";
55
"keyboard_shortcuts_can_be_changed" = "Většinu systémových zkratek můžete změnit v „Nastavení systému › Klávesnice › Klávesové zkratky“.";
6+
"keyboard_shortcut_disallowed" = "Modifikátor Option musí být kombinován s klávesou Command nebo Control.";
67
"ok" = "OK";
78
"space_key" = "Mezera";

Sources/KeyboardShortcuts/Localization/de.lproj/Localizable.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"keyboard_shortcut_used_by_menu_item" = "Dieses Tastaturkürzel kann nicht verwendet werden, da es bereits durch den Menüpunkt „%@” belegt ist.";
44
"keyboard_shortcut_used_by_system" = "Dieses Tastaturkürzel kann nicht verwendet werden, da es bereits systemweit verwendet wird.";
55
"keyboard_shortcuts_can_be_changed" = "Die meisten systemweiten Tastaturkürzel können unter „Systemeinstellungen › Tastatur › Tastaturkurzbefehle“ geändert werden.";
6+
"keyboard_shortcut_disallowed" = "Die Option-Taste muss mit der Befehlstaste oder der Steuerungstaste kombiniert werden.";
67
"ok" = "OK";
78
"space_key" = "Leer";

Sources/KeyboardShortcuts/Localization/en.lproj/Localizable.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"keyboard_shortcut_used_by_menu_item" = "This keyboard shortcut cannot be used as it’s already used by the “%@” menu item.";
44
"keyboard_shortcut_used_by_system" = "This keyboard shortcut cannot be used as it’s already a system-wide keyboard shortcut.";
55
"keyboard_shortcuts_can_be_changed" = "Most system-wide keyboard shortcuts can be changed in “System Settings › Keyboard › Keyboard Shortcuts”.";
6+
"keyboard_shortcut_disallowed" = "Option modifier must be combined with Command or Control.";
67
"force_use_shortcut" = "Use Anyway";
78
"ok" = "OK";
89
"space_key" = "Space";

Sources/KeyboardShortcuts/Localization/es.lproj/Localizable.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"keyboard_shortcut_used_by_menu_item" = "Este atajo de teclado no se puede utilizar ya que está siendo utilizado por el elemento de menú “%@”.";
44
"keyboard_shortcut_used_by_system" = "Este atajo de teclado no se puede utilizar ya que está siendo utilizado por un atajo del sistema operativo.";
55
"keyboard_shortcuts_can_be_changed" = "La mayoría de los atajos de teclado del sistema operativo pueden ser modificados en “Configuración del sistema › Teclado › Atajos de teclado“.";
6+
"keyboard_shortcut_disallowed" = "El modificador Option debe combinarse con Command o Control.";
67
"ok" = "Aceptar";
78
"space_key" = "Espacio";

Sources/KeyboardShortcuts/Localization/fr.lproj/Localizable.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"keyboard_shortcut_used_by_menu_item" = "Ce raccourci ne peut pas être utilisé, car il est déjà utilisé par le menu “%@”.";
44
"keyboard_shortcut_used_by_system" = "Ce raccourci ne peut pas être utilisé car il s'agit d'un raccourci déjà présent dans le système.";
55
"keyboard_shortcuts_can_be_changed" = "La plupart des raccourcis clavier de l'ensemble du système peuvent être modifiés en “Réglages du système… › Clavier › Raccourcis clavier…”.";
6+
"keyboard_shortcut_disallowed" = "Le modificateur Option doit être combiné avec Command ou Control.";
67
"ok" = "OK";
78
"space_key" = "Espace";

Sources/KeyboardShortcuts/Localization/hu.lproj/Localizable.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"keyboard_shortcut_used_by_menu_item" = "Ez a billentyűparancs nem használható mert már a “%@” menü elem használja.";
44
"keyboard_shortcut_used_by_system" = "Ez a billentyűparancs nem használható mert már egy rendszerszintü billentyűparancs.";
55
"keyboard_shortcuts_can_be_changed" = "A legtöbb rendszerszintü billentyűparancsot a “Rendszerbeállítások › Billentyűzet › Billentyűparancsok“ menüben meg lehet változtatni";
6+
"keyboard_shortcut_disallowed" = "Az Option módosítót a Command vagy Control billentyűvel együtt kell használni.";
67
"ok" = "OK";
78
"space_key" = "Szóköz";

0 commit comments

Comments
 (0)