Security Agent is going out of focus when triggering apple script via terminal

Hello Pro Scripters :slight_smile:
I have a very basic apple script that just invokes a uninstaller enters the password and hits the enter key
as below

tell application "<Our Custom Uninstaller for  App>"
	reopen
	activate
		tell application "System Events"
			delay 5
			keystroke "<I add my admin password here>"
			delay 5
			key code 36
		end tell
	delay 30
	tell application "System Events"
		key code 36
	end tell
end tell

This is very crude script but it works fine if I trigger it from Apple Script Editor
But the moment I add this script into the shell script and then try to invoke this apple script the Focus on that uninstaller window is lost and password is typed on the terminal instead of application

Is there anyway i can get the focus back on the window.

From accessibility inspector i see the UI hiearchy as follows

SecurityAgent(Application)
 - Untitled (standard window)
   Uninstaller App wants to make changes (text)
   Enter your password to allow this(text)
   Admin (text field)
   <empty description> (secure text field)

I’ve never seen the reopen command before.
What is this application “My Uninstaller App”?

For this, the answer is simple.

This is because the AppleScript execution environment called osascript, which is executed from the shell script, cannot execute “GUI Scripting” that forcibly manipulates menus, etc.

There are dozens of AppleScript execution environments, but osascript is one of the few execution environments that cannot use GUI Scripting.

Similarly, GUI Scripting is not available for AppleScript running on “Dropzone 4” or “Xojo 2023”.

@robertfern the reopen was just added a test to see if it focuses on the app but it didnt … the My Uninstaller App is just a Custom Uninstaller Designed inhouse that removes certain extensions. the issue that i see is with the apple script it doesnt focus on the prompt when I trigger the script via terminal.

Hi Robert.

There’s a brief mention of it here in the AppleScript Language Guide. (The paragraph immediately above the list disks entry.)

Any way to get a copy of the program to test GUI scripting on?