Simulator settings. Touch ID.


Alex Zavatone
 

Does anyone know of any way to save a simulator configuration so that it always loads with those settings?

I’ve created an AppleScript that turns on Touch ID for the iPhone 8 plus Simulator, but it seems like the least optimal solution out there for automated testing.

If anyone wants the script, I’ll be happy to sent it over. It checks if the menu is enabled, then clicks it and checks to make sure it’s enabled.

Thanks in advance,
Alex Zavatone


Alex Zavatone
 


On Sep 25, 2018, at 1:49 PM, Alex Zavatone via Groups.Io <zav@...> wrote:

Does anyone know of any way to save a simulator configuration so that it always loads with those settings?

I’ve created an AppleScript that turns on Touch ID for the iPhone 8 plus Simulator, but it seems like the least optimal solution out there for automated testing.

If anyone wants the script, I’ll be happy to sent it over.  It checks if the menu is enabled, then clicks it and checks to make sure it’s enabled.


Err, send, not sent.

Since I bothered to reply, here it is just in case anyone will find it helpful in their CI pipeline.


-- Alex Zavatone 10/25/2018
-- Tool to enable Touch ID assuming that the Simulator is displaying a device that allows Touch ID
-- Run from shell by using the following:
--
-- $ osascript myScriptFileName.scpt
-- $ osascript "Activate Touch ID in Simulator.scpt"
-- 
-- To do this, you will need to have created a user account on your Mac with admin privs other than your corporate account.
-- This will be needed to add Terminal and other controlling applications to the Accessibility item within the Privacy tab 
-- of the Security & Privacy Systems Preferences pane.
--

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions



on run
activate application "Simulator"
tell application "System Events"
tell process "Simulator"
-- set isChecked to my menuItemEnabledState()
set isChecked to (value of attribute "AXMenuItemMarkChar" of menu item "Enrolled" of menu "Touch ID" of menu item "Touch ID" of menu "Hardware" of menu bar item "Hardware" of menu bar 1) is "✓" -- check if Status is "Available"    
-- end tell


log isChecked


if isChecked = false then
log "Touch ID is disabled."
-- tell process "Simulator"
-- activate
delay 1
-- set isChecked to my menuItemEnabledState()
set isChecked to (value of attribute "AXMenuItemMarkChar" of menu item "Enrolled" of menu "Touch ID" of menu item "Touch ID" of menu "Hardware" of menu bar item "Hardware" of menu bar 1) is "✓" -- check if Status is "Available"    
click menu item "Enrolled" of menu "Touch ID" of menu item "Touch ID" of menu "Hardware" of menu bar item "Hardware" of menu bar 1
delay 1
set isChecked to (value of attribute "AXMenuItemMarkChar" of menu item "Enrolled" of menu "Touch ID" of menu item "Touch ID" of menu "Hardware" of menu bar item "Hardware" of menu bar 1) is "✓" -- check if Status is "Available"    


set maxTries to 0
repeat while isChecked = false and maxTries < 5
-- set isChecked to my menuItemEnabledState()


set maxTries to maxTries + 1
click menu item "Enrolled" of menu "Touch ID" of menu item "Touch ID" of menu "Hardware" of menu bar item "Hardware" of menu bar 1
set isChecked to (value of attribute "AXMenuItemMarkChar" of menu item "Enrolled" of menu "Touch ID" of menu item "Touch ID" of menu "Hardware" of menu bar item "Hardware" of menu bar 1) is "✓" -- check if Status is "Available"    


end repeat


-- set isChecked to menuItemEnabledState()
set isChecked to (value of attribute "AXMenuItemMarkChar" of menu item "Enrolled" of menu "Touch ID" of menu item "Touch ID" of menu "Hardware" of menu bar item "Hardware" of menu bar 1) is "✓" -- check if Status is "Available"    


if isChecked = true then
log "Touch ID has been enabled. "


display dialog "Touch ID has been enabled." giving up after 1
else
log "Touch ID is still disabled after " & maxTries & " attempts."


end if


-- end tell
else
log "Touch ID is already enabled."
end if


log isChecked
end tell
end tell
end run

-- Though this should work, it caused errors resulting in the menu item not being selected.
on menuItemEnabledState()
-- tell application "System Events"
-- tell process "Simulator"
-- set isChecked to (value of attribute "AXMenuItemMarkChar" of menu item "Enrolled" of menu "Touch ID" of menu item "Touch ID" of menu "Hardware" of menu bar item "Hardware" of menu bar 1) is "✓" -- check if Status is "Available" 
-- return isChecked
-- end tell
-- end tell
end menuItemEnabledState