Jump to content

How to re-trigger hotkey in applescript?


Recommended Posts

Posted

Hi there,

 

I've using workflow to supply some specified purpose in some applications via hotkey, for example:

 

Hotkey (cmd+g) -> run osascript:

 

If the frontmost app is not Evernote then

    error -127

else

    get the source url of the selected note

    tell safari to open the url

end if

 

Now my question is, because alfred will overwrite the hotkeys, in some other applications which also use the cmd+g, will not trigger the corresponded events. Hence, I need some scripts to replace the "error -127" to re-trigger "cmd+g" again.

 

I've used

 

    tell application "System Events" to key code 5 using {command down}

 

or

 

    tell application "System Events" to keystroke "g" using command down

 

But they are not working, and my front most application will become very slow :\ It seems System Event will execute for almost half minutes, which is unreasonable in my opinion.

 

Am I miss something? 

 

Thank you!

Posted

Hi there,

 

I've using workflow to supply some specified purpose in some applications via hotkey, for example:

 

Hotkey (cmd+g) -> run osascript:

 

If the frontmost app is not Evernote then

    error -127

else

    get the source url of the selected note

    tell safari to open the url

end if

 

Now my question is, because alfred will overwrite the hotkeys, in some other applications which also use the cmd+g, will not trigger the corresponded events. Hence, I need some scripts to replace the "error -127" to re-trigger "cmd+g" again.

 

I've used

 

    tell application "System Events" to key code 5 using {command down}

 

or

 

    tell application "System Events" to keystroke "g" using command down

 

But they are not working, and my front most application will become very slow :\ It seems System Event will execute for almost half minutes, which is unreasonable in my opinion.

 

Am I miss something? 

 

Thank you!

 

I believe you have to do...

tell application "System Events"
  tell process "Evernote" to keystroke "g" using command down
end tell
Posted

Thank you David Ferguson. I know what causes my problem now, after tracing some logs.

 

My misunderstood is the keystroke is actually success, however, every key strokes -- even tell process to keystroke -- are still go back to Alfred. And it causes an infinite loop with many key strokes, which cause my entire OS slowing down :(

 

Before an application-specified howkey of alfred is supported, I will use the menubar to call the desired function for some specified applications. It's still not a universal and great solution because various applications will not put the items with same hotkey in the same menubar position. But it's still better than solwing down the system :P

 

Thank you.

Posted (edited)

Hi there,

 

I've using workflow to supply some specified purpose in some applications via hotkey, for example:

 

Hotkey (cmd+g) -> run osascript:

 

If the frontmost app is not Evernote then

    error -127

else

    get the source url of the selected note

    tell safari to open the url

end if

 

Now my question is, because alfred will overwrite the hotkeys, in some other applications which also use the cmd+g, will not trigger the corresponded events. Hence, I need some scripts to replace the "error -127" to re-trigger "cmd+g" again.

 

I've used

 

    tell application "System Events" to key code 5 using {command down}

 

or

 

    tell application "System Events" to keystroke "g" using command down

 

But they are not working, and my front most application will become very slow :\ It seems System Event will execute for almost half minutes, which is unreasonable in my opinion.

 

Am I miss something? 

 

Thank you!

 

You might be interested in this feature request. It describes 'scoped' workflows, that are only activated when certain apps are frontmost.

 

Cheers :)

Edited by Tyler Eich

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...