Reputation: 724
I have n
instances of xcode ios simulator and I want to switch a focus on instance with specified id.
I tried next things:
open -a Simulator --args -CurrentDeviceUDID <id>
. But it opens the last focused simulator instance instead of the instance with passed id.xcrun simctl openurl <id> "https://www.google.com"
, but it doesn't change the focus.tell application "System Events" to tell process "Simulator"
perform action "AXRaise" of window 0
end tell
Do you have any idea, how to do this?
Upvotes: 0
Views: 742
Reputation: 7555
The following example AppleScript code is one method that works for me:
Example AppleScript code:
tell application "Simulator"
activate
set winName to the name of ¬
the first window ¬
whose visible is true ¬
and index is not 1
end tell
tell application "System Events" to ¬
perform action "AXRaise" of ¬
window winName of ¬
process "Simulator"
Notes:
The example AppleScript code assumes you have two Simulator windows visible, and it will toggle raising between the two. Obviously this is just an example and you'll need to modify and incorporate the methodology into you own code.
In your example AppleScript code, window n refers to its index as in:
index (integer) : The index of the window, ordered front to back.
The quoted line above is from the AppleScript dictionary for Simulator in Script Editor.
The z-order of index starts at: 1
Using System Events and perform action "AXRaise" of window ...
can be done by it's name
property or it's index
property.
The example AppleScript code, shown above, was tested in Script Editor under macOS Catalina with Language & Region settings in System Preferences set to English (US) — Primary and worked for me without issue1.
Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5
, with the value of the delay set appropriately.
Upvotes: 1