Jump to content

Pass "Enter" to app "Cisco AnyConnect"


Recommended Posts

Posted

Hi Community,

I just bought Alfred PowerPack because I am annoyed of some recurring tasks like connecting to the companies VPN.

The process is:

  1. Start Cisco AnyConnect
  2. Hit Enter
  3. Enter static password + Hit Enter
  4. Load a lookup table pdf
  5. identify values in pdf
  6. enter values in Cisco AnyConnect + Hit Enter
  7. Hit enter 

 

Since I do no think, I will be able to automate the whole process, I would already be helpful to automate some steps.

 

What have I managed so far?

Open "Cisco AnyConnect" and "PDF" via a single hot-key.

 

Where am I struggling at the moment?

Passing the "Enter" to Cisco AnyConnect from step 2.

Was using "Dispatch Key Combo" but it behave likes no button is pressed,

Any ideas why?

image.png.b8792e9464ac4ff280fbfc105e58138e.png

 

Kind regards and Merry X-mas

 

Matthias

Posted
1 hour ago, MatthiasW said:

Any ideas why?

 

The problem is almost certainly that the key combo is being fired before the app is running. Asking the system to open files or applications (which is what Alfred is doing) is asynchronous. The OS immediately replies "OK". It doesn't wait until the application is actually running or the file is open. So your simulated keypress is being fired long before AnyConnect is running and ready to receive it.

 

The solution is to use AppleScript to launch the application, wait until it's running, and then simulate the keystroke. Like in this script @GuiB wrote for Firefox.

 

I can't test it because I don't have AnyConnect, but you probably want something like this:

tell application "Cisco AnyConnect"
	activate
	repeat 50 times -- wait up to 5 seconds for app to activate
		if frontmost then exit repeat
		delay 0.1
	end repeat
end tell
tell application "System Events" to key code 36 -- simulate 

Replace your Lauch Apps/Files action & Key Combo with a Run Script action with Language = /usr/bin/osascript (AS), and put the above script in it.

Posted
13 minutes ago, deanishe said:

I will give this a try as well.

Thanks

13 minutes ago, deanishe said:

The problem is almost certainly that the key combo is being fired before the app is running. Asking the system to open files or applications (which is what Alfred is doing) is asynchronous. The OS immediately replies "OK". It doesn't wait until the application is actually running or the file is open. So your simulated keypress is being fired long before AnyConnect is running and ready to receive it.

 

The solution is to use AppleScript to launch the application, wait until it's running, and then simulate the keystroke. Like in this script @GuiB wrote for Firefox.

 

I can't test it because I don't have AnyConnect, but you probably want something like this:


tell application "Cisco AnyConnect"
	activate
	repeat 50 times -- wait up to 5 seconds for app to activate
		if frontmost then exit repeat
		delay 0.1
	end repeat
end tell
tell application "System Events" to key code 36 -- simulate 

Replace your Lauch Apps/Files action & Key Combo with a Run Script action with Language = /usr/bin/osascript (AS), and put the above script in it.

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...