Unable to sign in after inserting username & password (SecureInput)

I’m trying to automate signing in to an application for 10 users. I’ve been able to successfully loop entering the users account name and the users passwords, but I can never get the “Sign In” button to ‘light up’ after I input the username/password so I can never ‘press’ return or ‘click’ the sign in button.

Here’s sort of what the application looks like:

Here’s the code I’m using:

tell application "MyApp" to activate
delay 1
tell application "System Events"
	tell process "MyApp"
		set frontmost to true
		click menu item "Sign In…" of menu "Account" of menu bar 1
	end tell
end tell
--this successfully starts the application, clicks the top menu button "Account" and the sub-menu "Sign in..." and brings up the sign in screen I listed above

delay 2

set userList to {"jim", "pam", "oscar", "stanley", "michael", "dwight", "creed", "angela", "kevin", "andy"}
repeat with a from 1 to length of userList
	
	set userName to item a of userList
	set userPass to "hunter2"
	
	tell application "System Events"
		tell process "MyApp"
			set value of text field 1 of window 1 to userName
			set value of text field 2 of window 1 to userPass
		end tell
	end tell
end repeat
--this successfully enters the username and password, starting with "jim", but it never 'lights up' the "Sign In" button in the bottom right of the image, so I cannot interact with it at all.

delay 10
--then it repeats with the window again, this works fine.

I think this has something to do with the Secure Input feature on MacOS.

Here’s a breakdown of some of the window information using Accessibility Inspector from XCode:

May you try to add an instruction ?

tell application "System Events"
	tell process "MyApp"
		set frontmost to true -- ADDED
		set value of text field 1 of window 1 to userName
		set value of text field 2 of window 1 to userPass
	end tell
	end tell

which may be cleaned as :

tell application "System Events" to tell process "MyApp" -- EDITED
	set frontmost to true -- ADDED
	tell window 1 -- ADDED
		set value of text field 1 to userName -- EDITED
		set value of text field 2 to userPass -- EDITED
	end tell
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 9 avril 2020 17:52:40

Thank you for your help! It looks like it still fails in the same fashion.

		tell application "System Events" to tell process "MyApp"
			set frontmost to true
			tell window 1
				set value of text field 1 to userName
				set value of text field 2 to userPass
			end tell
		end tell

It still enters the values just as it did before but it never allows me to sign in.

Have you give permission to your app in the prefpane Security ?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 9 avril 2020 18:41:33

Yes I have, thank you! I’ve allowed the Script Editor app and exported the script as an application, and allowed that application within System Preferences > Security & Privacy > Privacy > Accessibility, Full Disk Access, Automation, and Developer tools.

Interestingly enough, after

set value of text field 1 to userName

if I add a delay and manually click on the “Password” text box (text field 2) before it fills then it works.

Is there any way to activate that box or force the cursor to click it?

click text field 2

doesn’t work.

It seems that the full support of the UI elements is not implemented.
Happily it’s easy to solve.


# Download cliclick from : <https://www.bluem.net/en/mac/cliclick/>
# Install it in the folder "/usr/local/bin/"

tell application "System Events" to tell process "MyApp" -- EDITED
	set frontmost to true -- ADDED
	tell window 1 -- ADDED
		set value of text field 1 to userName -- EDITED
		set {x, y} to position of text field 1
		tell me to do shell script "/usr/local/bin/cliclick c:" & (x + 2) & "," & (y + 2)
		set value of text field 2 to userPass -- EDITED
		-- delay .1
		set {x, y} to position of text field 2
		tell me to do shell script "/usr/local/bin/cliclick c:" & (x + 2) & "," & (y + 2)
		-- delay .1
	end tell
end tell

Enable the delay instructions if the script doesn’t do the job as is.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 9 avril 2020 21:43:15

Appreciate the information as always! My goal here is to stay within the native MacOS environment if possible. I may need to try to use automator or a shell script to get it working. Thank you for the alternative though!

My proposal rely upon a shell script and cliclick may be embedded in your package.
I just call it from its “standard” location
Is it doing the full job ?

If you search in this forum for cliclick you will find ASObjC proposals posted by KniazidisR described as replacing the use of cliclick.
Alas I never got them to work but, maybe I missed something.

You may also edit your app so that it fully support the two text fields which it fails to do at this time.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 9 avril 2020 22:43:32

Hey dude, thanks for all the help - I was able to figure it out. I can apparently just refeference the tab key and it will treat it will tab to the correct box!

I have one last issue. Is there a way to make the script pause and wait for a window to appear, then move forward to the next part of the script? I want to make it so I don’t have to rely on waiting for “delay 10” or whatever I choose - since this will run on a few computers that have different speeds at opening the app (old computers).

Here’s the script as I have it right now, working great:

set userList to {"jim", "pam", "oscar", "stanley", "michael", "dwight", "creed", "angela", "kevin", "andy"}
repeat with a from 1 to length of userList

--this sets my array/list correctly and I believe it starts the loop process to run through each username until it's done
	
	tell application "MyApp" to activate
	delay 1
--I would like the script to pause right here and wait until the "MyApp" application running
	tell application "System Events"
		tell process "MyApp"
			set frontmost to true
			click menu item "Sign In As…" of menu "Account" of menu bar 1
		end tell
	end tell
	
--this tells the app to run, works great (the app itself starts without a UI so I need to do this to bring the window to the front).
	
	delay 10
-- I would like the next part of the script to only start when the "MyApp" window is active/frontmost, then I could replace the delay 10
	
	tell application "System Events"
		tell process "MyApp"
			click menu button "Options" of window 1
			keystroke "e"
			key code 36
			keystroke "u"
			key code 36
		end tell
	end tell
	
--this brings up the sign in window
	
	delay 10
--Again I would like it to wait until the sign in window is up rather than having the delay 10
	
	set userName to item a of userList
	set userPass to "hunter2"
	
	tell application "System Events" to tell process "MyApp"
		set frontmost to true
		tell window 1
			set value of text field 2 to ""
			set value of text field 1 to ""
			set value of text field 1 to userName
			key code 48
			set value of text field 2 to userPass
			delay 0.4
			click button "Sign In"
			delay 4
		end tell
	end tell
end repeat

delay 10

--this completes the loop and it starts again, which works perfectly. The "Sign In" window disappears and the "MyApp" application closes, so the whole thing needs to restart when the sign in window disappears or when it detects the app not running anymore

Sorry for all the info, I just tried to do it myself and I keep breaking it, possibly because I’m using if/else/then wrong.

Hello. I can’t test but the code below is supposed to do the job once you will have replace “???” by the real name of the wanted window.

set userList to {"jim", "pam", "oscar", "stanley", "michael", "dwight", "creed", "angela", "kevin", "andy"}


--this sets my array/list correctly and I believe it starts the loop process to run through each username until it's done

tell application "MyApp" to activate
tell application "System Events"
	repeat until exists (process 1 whose name is "MyApp")
		delay 0.1
	end repeat
end tell

-- 	Now the process is available, enter the main loop
repeat with userName in userList
	tell application "System Events"
		
		
		tell process "MyApp"
			set frontmost to true
			click menu item "Sign In As…" of menu "Account" of menu bar 1
		end tell
	end tell
	
	
	tell application "System Events" to tell process "MyApp"
		set frontmost to true
		repeat until exists window "????" -- Edit according to the name of the wanted window
			delay 0.1
		end repeat
		click menu button "Options" of window 1 -- may be a good idea to use the real name of the window
		keystroke "e"
		key code 36
		keystroke "u"
		key code 36
		-- end tell
		
		--this brings up the sign in window
		
		set userPass to "hunter2" -- Not sure that it's a good idea to hardcode a passWord
		
		-- tell application "System Events" to tell process "MyApp"
		-- set frontmost to true
		repeat until exists window "????" -- Edit according to the name of the wanted window
			delay 0.1
		end repeat
		tell window 1 -- may be a good idea to use the real name of the window
			set value of text field 2 to ""-- It was here but I'm not sure that it's really needed
			set value of text field 1 to ""-- It was here but I'm not sure that it's really needed
			set value of text field 1 to userName as string
			key code 48
			set value of text field 2 to userPass
			delay 0.4
			click button "Sign In"
			delay 4 -- It was here but I'm not sure that it's really needed
		end tell
	end tell
	
end repeat

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 13 avril 2020 18:01:17

Looks great! The only issue is that the window doesn’t actually contain a title.

The “Label”, “Title” and “Value” are empty, according to xcode. Any way around that if I have the parent window or if I can reference if a certain button of the app exists? Something like the “Sign In” button?

It’s a bit boring to have to play sooth sayers. On your first screenshot the window appear with what resemble a title : “MYAPP Sign On”.

set userList to {"jim", "pam", "oscar", "stanley", "michael", "dwight", "creed", "angela", "kevin", "andy"}


--this sets my array/list correctly and I believe it starts the loop process to run through each username until it's done

tell application "MyApp" to activate
tell application "System Events"
	repeat until exists (process 1 whose name is "MyApp")
		delay 0.1
	end repeat
end tell

-- 	Now the process is available, enter the main loop
repeat with userName in userList
	tell application "System Events"
		
		
		tell process "MyApp"
			set frontmost to true
			click menu item "Sign In As…" of menu "Account" of menu bar 1
		end tell
	end tell
	
	
	tell application "System Events" to tell process "MyApp"
		set frontmost to true
		repeat
			try
				tell window 1 to if name of menu buttons contains "Options" then exit repeat
			end try
			delay 0.1
		end repeat
		click menu button "Options" of window 1 -- may be a good idea to use the real name of the window
		keystroke "e"
		key code 36
		keystroke "u"
		key code 36
		-- end tell
		
		--this brings up the sign in window
		
		set userPass to "hunter2" -- Not sure that it's a good idea to hardcode a passWord
		
		-- tell application "System Events" to tell process "MyApp"
		-- set frontmost to true
		repeat
			try
				tell window 1 to if name of buttons contains "Sign In" then exit repeat
			end try
			delay 0.1
		end repeat
		tell window 1 -- may be a good idea to use the real name of the window
			set value of text field 2 to "" -- It was here but I'm not sure that it's really needed
			set value of text field 1 to "" -- It was here but I'm not sure that it's really needed
			set value of text field 1 to userName as string
			key code 48
			set value of text field 2 to userPass
			delay 0.4
			click button "Sign In"
			delay 4 -- It was here but I'm not sure that it's really needed
		end tell
	end tell
	
end repeat

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 14 avril 2020 09:25:54

How are you sure that the first window which will appear is the one supposed to be signed as “jim”, that the second will be the one supposed to be signed as “pam” … ?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 14 avril 2020 10:11:12

Sorry about the back and forth, feel free to stop responding to me at any time (or tell me to screw off, that works too) - my intention wasn’t to give you a task, I’m trying to learn as much as I can about Applescript and I was able to get as far as I could after a few days of trying.

This is the breakdown of the actual window as shown in Accessibility Inspector from Xcode

Sadly the developers failed to add much information about the window title.

Is the script posted in message #12 working ?

I repeat what I wrote in message #13, are you sure that, when a window become available, it’s the one supposed to be signed with a given string ?

I’m not sure of that and have no info about the way this possible problem may be treated.

Is there a way to get infos about the machine owning the window which is available ?

Is the app available so that I may try to understand how it’s really behaving?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 15 avril 2020 14:02:41