From d404f4f369c7bb219871a8351e0b25145c32ef70 Mon Sep 17 00:00:00 2001 From: kenji Date: Wed, 12 May 2021 17:06:19 +0200 Subject: [PATCH] Use newer APIs to launch applications to fix issue #38 --- Thor/ShortcutMonitor.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Thor/ShortcutMonitor.swift b/Thor/ShortcutMonitor.swift index 86bcd22..debc7f4 100644 --- a/Thor/ShortcutMonitor.swift +++ b/Thor/ShortcutMonitor.swift @@ -7,6 +7,7 @@ // import Foundation +import Cocoa import MASShortcut struct ShortcutMonitor { @@ -22,7 +23,18 @@ struct ShortcutMonitor { frontmostAppIdentifier == targetAppIdentifier { NSRunningApplication.runningApplications(withBundleIdentifier: frontmostAppIdentifier).first?.hide() } else { - NSWorkspace.shared.launchApplication(app.appName) + if #available(macOS 10.15, *) { + let configuration = NSWorkspace.OpenConfiguration() + configuration.activates = true + NSWorkspace.shared.openApplication(at: app.appBundleURL, + configuration: configuration) { _, error in + if let error = error { + NSLog("ERROR: \(error)") + } + } + } else { + NSWorkspace.shared.launchApplication(app.appName) + } } }) }