@@ -121,26 +121,39 @@ public enum Environment {
121121 let bundleName = Bundle . main
122122 . object ( forInfoDictionaryKey: " EXTENSION_BUNDLE_NAME " ) as! String
123123
124- /// check if menu is open, if not, click the menu item.
125- let appleScript = """
126- tell application " System Events "
127- set theprocs to every process whose unix id is \( activeXcode. processIdentifier)
128- repeat with proc in theprocs
129- set the frontmost of proc to true
130- tell proc
131- repeat with theMenu in menus of menu bar 1
132- set theValue to value of attribute " AXVisibleChildren " of theMenu
133- if theValue is not {} then
134- return
135- end if
136- end repeat
137- click menu item " \( name) " of menu 1 of menu item " \( bundleName) " of menu 1 of menu bar item " Editor " of menu bar 1
138- end tell
139- end repeat
140- end tell
141- """
142-
143- try await runAppleScript ( appleScript)
124+ let app = AXUIElementCreateApplication ( activeXcode. processIdentifier)
125+ if let editorMenu = app. menuBar? . child ( title: " Editor " ) ,
126+ let commandMenu = editorMenu. child ( title: bundleName) ,
127+ let button = commandMenu. child ( title: name, description: " menu bar item " )
128+ {
129+ AXUIElementPerformAction ( button, " press " as CFString )
130+ } else if let commandMenu = app. menuBar? . child ( title: bundleName) ,
131+ let button = commandMenu. child ( title: name, description: " menu bar item " )
132+ {
133+ AXUIElementPerformAction ( button, " press " as CFString )
134+ }
135+
136+ // /// check if menu is open, if not, click the menu item.
137+ // let appleScript = """
138+ // tell application "System Events"
139+ // set theprocs to every process whose unix id is \(activeXcode.processIdentifier)
140+ // repeat with proc in theprocs
141+ // set the frontmost of proc to true
142+ // tell proc
143+ // repeat with theMenu in menus of menu bar 1
144+ // set theValue to value of attribute "AXVisibleChildren" of theMenu
145+ // if theValue is not {} then
146+ // return
147+ // end if
148+ // end repeat
149+ // click menu item "\(name)" of menu 1 of menu item "\(bundleName)" of menu 1 of
150+ // menu bar item "Editor" of menu bar 1
151+ // end tell
152+ // end repeat
153+ // end tell
154+ // """
155+ //
156+ // try await runAppleScript(appleScript)
144157 }
145158
146159 public static var makeXcodeActive : ( ) async throws -> Void = {
0 commit comments