mirror of
https://github.com/Louis-CFM/coucou.git
synced 2026-12-07 07:32:35 +09:00
18 lines
887 B
Swift
18 lines
887 B
Swift
import AppKit
|
|
|
|
extension TerminalTarget {
|
|
/// Brings the session's terminal to the front: the app the session runs in first,
|
|
/// then the first running known terminal. Returns false if none is running.
|
|
@discardableResult
|
|
static func activate(sessionBundleId: String?) -> Bool {
|
|
let apps = NSWorkspace.shared.runningApplications
|
|
let running = Set(apps.compactMap(\.bundleIdentifier))
|
|
guard let id = pick(sessionBundleId: sessionBundleId, running: running),
|
|
let url = apps.first(where: { $0.bundleIdentifier == id })?.bundleURL else { return false }
|
|
// Not NSRunningApplication.activate(): since macOS 14 it is ignored when called
|
|
// from an app that is not active, and the island never is.
|
|
NSWorkspace.shared.openApplication(at: url, configuration: .init(), completionHandler: nil)
|
|
return true
|
|
}
|
|
}
|