f.lux f.lux forum
    • Recent
    • Popular
    • Register
    • Login

    How to create keyboard shortcuts

    macOS
    9
    12
    10.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      musafirsafwan
      last edited by

      Thank you.. This works.. Any way to make it faster?

      T 1 Reply Last reply Reply Quote 0
      • T
        ttime @musafirsafwan
        last edited by

        @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
        
        1 Reply Last reply Reply Quote 0
        • Jazor CH HoJ
          Jazor CH Ho
          last edited by

          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

          T 1 Reply Last reply Reply Quote 0
          • T
            ttime @Jazor CH Ho
            last edited by ttime

            @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

            Jazor CH HoJ 1 Reply Last reply Reply Quote 0
            • Jazor CH HoJ
              Jazor CH Ho @ttime
              last edited by

              @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

              T 1 Reply Last reply Reply Quote 0
              • T
                ttime @Jazor CH Ho
                last edited by ttime

                @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

                1 Reply Last reply Reply Quote 0
                • J
                  jgclark
                  last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • S
                    sharmaanitajii
                    last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • A
                      Aaron1551
                      last edited by

                      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
                      
                      T 1 Reply Last reply Reply Quote 0
                      • T
                        teefeld @Aaron1551
                        last edited by

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

                        1 Reply Last reply Reply Quote 0
                        • G
                          gulsimsur
                          last edited by

                          Thanks for great share

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          Copyright © 2014 NodeBB Forums | Contributors