Index Error

Try to get a simple script working. The idea behind it is make it simpler to log on to my work network.

When running the script in the editor, everything works fine.

When running it as an application, I keep getting this error.

“System Events got an error: Can’t get window 1 of process “Cisco AnyConnect Secure Mobility Client”. Invalid index. (-1719)”

Can anybody shed some light on the situation?

tell application "Finder"
	activate
	open application file "Cisco AnyConnect Secure Mobility Client.app" of folder "Cisco" of folder "Applications" of startup disk
end tell
delay 2
tell application "System Events" to tell process "Cisco AnyConnect Secure Mobility Client"
	click button "Connect Anyway" of window 1
	delay 2
	keystroke "password" -- password
	delay 2
	key code 36
end tell


Model: MacBook Pro
AppleScript: 2.7
Browser: Safari 537.36
Operating System: Mac OS X (10.10)

Try to insert one instruction.

tell application "System Events" to tell process "Cisco AnyConnect Secure Mobility Client"
   set frontmost to true # ADDED
   click button "Connect Anyway" of window 1

I’m not sure that it will solve the problem because, as far as I remember, it was required by 10.11, not 10.10.
But after all, my memory may be wrong.

Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) lundi 13 février 2017 11:09:58

It works with and without that added line.

Hi.

It looks as if you got the beginning of the script by recording your own actions. You may get a more reliable start if you change .

tell application "Finder"
	activate
	open application file "Cisco AnyConnect Secure Mobility Client.app" of folder "Cisco" of folder "Applications" of startup disk
end tell
delay 2

. to either .

tell application "Cisco AnyConnect Secure Mobility Client" to activate

. or .

activate application "Cisco AnyConnect Secure Mobility Client"

In the original, the script waits for two seconds after the Finder acknowledges having opened the file. In the alternative versions, it waits until the “Cisco AnyConnect Secure Mobility Client” application itself acknowledges that it’s up and running.