@@ -549,15 +549,16 @@ extension XcodeAppInstanceInspector {
549549// MARK: - Triggering Command
550550
551551public extension XcodeAppInstanceInspector {
552- func triggerCopilotCommand( name: String ) async throws {
552+ func triggerCopilotCommand( name: String , activateXcode : Bool = true ) async throws {
553553 let bundleName = Bundle . main
554554 . object ( forInfoDictionaryKey: " EXTENSION_BUNDLE_NAME " ) as! String
555- try await triggerMenuItem ( path: [ " Editor " , bundleName, name] )
555+ try await triggerMenuItem ( path: [ " Editor " , bundleName, name] , activateXcode : activateXcode )
556556 }
557557}
558558
559559public extension AppInstanceInspector {
560- func triggerMenuItem( path: [ String ] ) async throws {
560+ @MainActor
561+ func triggerMenuItem( path: [ String ] , activateXcode: Bool ) async throws {
561562 guard !path. isEmpty else { return }
562563
563564 struct CantRunCommand : Error , LocalizedError {
@@ -567,7 +568,17 @@ public extension AppInstanceInspector {
567568 }
568569 }
569570
570- if !runningApplication. isActive { runningApplication. activate ( ) }
571+ if activateXcode {
572+ if !runningApplication. activate ( ) {
573+ throw CantRunCommand ( path: path)
574+ }
575+ } else {
576+ if !runningApplication. isActive {
577+ throw CantRunCommand ( path: path)
578+ }
579+ }
580+
581+ await Task . yield ( )
571582
572583 if UserDefaults . shared. value ( for: \. triggerActionWithAccessibilityAPI) {
573584 let app = AXUIElementCreateApplication ( runningApplication. processIdentifier)
@@ -617,7 +628,6 @@ public extension AppInstanceInspector {
617628 set theprocs to every process whose unix id is \
618629 \( runningApplication. processIdentifier)
619630 repeat with proc in theprocs
620- set the frontmost of proc to true
621631 tell proc
622632 repeat with theMenu in menus of menu bar 1
623633 set theValue to value of attribute " AXVisibleChildren " of theMenu
0 commit comments