How to create keyboard shortcuts
-
@musafirsafwan said in How to create keyboard shortcuts:
Thank you.. This works.. Any way to make it faster?
Try this:
-- Settings -- property mainItem : "Disable" -- set to "Preferences...", "Color Effects", "Disable", etc., -- make sure to use quote marks. property subItem : "for an hour" -- set to submenu item, if there is one. Use "for this app" with Disable, -- to toggle disable for the current application. -- end of Settings -- if mainItem is "Disable" and subItem is "for this app" then set subItem to 3 tell application "System Events" tell application process "Flux" tell menu bar 1 tell menu bar item 1 try with timeout of 0.1 seconds perform action "AXPress" end timeout end try end tell end tell end tell end tell do shell script "killall 'System Events'" tell application "System Events" tell application process "Flux" tell menu bar 1 tell menu bar item 1 tell menu 1 tell menu item mainItem perform action "AXPress" end tell if menu 1 of menu item mainItem exists then tell menu 1 of menu item mainItem tell menu item subItem perform action "AXPress" end tell end tell end if end tell end tell end tell if mainItem is "Preferences..." then set frontmost to true end tell end tell
-
Hi @ttime
I have tried many ways including many other scripts on the web,
however this is the only one that actually works.
Impressive work!
Others were not able to trigger menu bar icons as apparently they are not "named".Anyway,
I am just trying to play around with your script so that it would work together with apps like bartender. Is there any way to achieve so?Regards,
Jazor -
@Jazor-CH-Ho said in How to create keyboard shortcuts:
I am just trying to play around with your script so that it would work together with apps like bartender. Is there any way to achieve so?
I don't have Bartender, but if the script doesn't work with Bartender then probably Bartender is messing up the menu structure.
When it comes to identify GUI elements like for example menu items, there are a couple of tools that make your life easier:
- Script Debugger: A really superior replacement for Apple's Script Editor. It shows you lots of valuable information on GUI elements. Well worth the price if you are regularly applescripting.
- Accessibility Inspector: Shows you real-time information on GUI elements. Comes with Xcode, free.
- UI Browser: Similar to Accessibility Inspector but way more comfortable.
– Tom
-
@ttime
Thanks for the reply.I have managed to find a way using Alfred. All I did was telling Alfred to press Bartender's hotkey then run your script, and it worked.
Thanks again for your code.
Regards
-
@Jazor-CH-Ho said in How to create keyboard shortcuts:
All I did was telling Alfred to press Bartender's hotkey then run your script
You can also press hotkeys from within the script:
For example if your Bartender hotkey is Shift-Control-Option-Command-M then insert these lines just after the first occurrence of
tell application "System Events"
:keystroke "m" using {command down, control down, option down, shift down} delay 0.2
Adapt the keystroke command to your needs. Perhaps the delay isn't necessary.
– Tom
-
I've just found this script, which appears to be just what I need. But I wonder if this is now out of date? On v39.987 I get this error:
error "System Events got an error: Can’t get menu item "Color Effects" of menu 1 of menu bar item 1 of menu bar 1 of process "Flux"." number -1728 from menu item "Color Effects" of menu 1 of menu bar item 1 of menu bar 1 of process "Flux"
(I'm trying to create a Darkroom mode toggle, so mainItem is "Color Effects" and subItem is "Darkroom".)
-
This post is deleted! -
Here, I fixed it!!
-- Settings -- property mainItem : "Color Effects" -- set to "Preferences...", "Color Effects", "Disable", etc., -- make sure to use quote marks. property subItem : "Darkroom" -- set to submenu item, if there is one. Use "for this app" with Disable, -- to toggle disable for the current application. -- end of Settings -- if mainItem is "Disable" and subItem is "for this app" then set subItem to 3 tell application "System Events" tell application process "Flux" tell menu bar 2 tell menu bar item 1 try with timeout of 0.1 seconds perform action "AXPress" end timeout end try end tell end tell end tell end tell do shell script "killall 'System Events'" tell application "System Events" tell application process "Flux" tell menu bar 2 tell menu bar item 1 tell menu 1 tell menu item mainItem perform action "AXPress" end tell if menu 1 of menu item mainItem exists then tell menu 1 of menu item mainItem tell menu item subItem perform action "AXPress" end tell end tell end if end tell end tell end tell if mainItem is "Preferences..." then set frontmost to true end tell end tell
-
@Aaron1551, this works perfect! But how can I customize it to go in movie mode? I can't figure out what exactly to change to make it work.
-
Thanks for great share