MatthiasW Posted December 24, 2019 Posted December 24, 2019 Hi Community, I just bought Alfred PowerPack because I am annoyed of some recurring tasks like connecting to the companies VPN. The process is: Start Cisco AnyConnect Hit Enter Enter static password + Hit Enter Load a lookup table pdf identify values in pdf enter values in Cisco AnyConnect + Hit Enter 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? Kind regards and Merry X-mas Matthias
deanishe Posted December 24, 2019 Posted December 24, 2019 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. MatthiasW 1
MatthiasW Posted December 24, 2019 Author Posted December 24, 2019 Hi, I have added a one second delay between launching the app and the key combo. Now it's working.
MatthiasW Posted December 24, 2019 Author Posted December 24, 2019 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now