jkbrzt / macos-fn-toggle

A macOS app to quickly toggle the behavior of the fn key.
https://twitter.com/jakubroztocil
MIT License
233 stars 30 forks source link

MacBook with Touch bar not supported #9

Open felipekunzler opened 4 years ago

felipekunzler commented 4 years ago

MacBooks with Touch bar have a different setting for switching between fn keys and app controls. Running the current script ticks Adjust keyboard brightness in low light instead. Screen Shot 2020-06-18 at 10 47 34

Screen Shot 2020-06-18 at 10 48 50
jkbrzt commented 4 years ago

@felipekunzler you might wanna use https://github.com/Pyroh/Fluor instead, which is actively maintained and works great!

felipekunzler commented 4 years ago

I believe what Fluor does (have a default for each app) is already possible within Mac preferences, see: https://www.imore.com/how-make-function-keys-default-touch-bar-display

I was actually looking for a quick toggle really, there are some cases where that's still needed. This script seems to do the trick:

tell application "System Preferences"
    reveal anchor "keyboardTab" of pane id "com.apple.preference.keyboard"
end tell

tell application "System Events"
    tell application process "System Preferences"
        set thePopup to pop up button 2 of tab group 1 of window "Keyboard"
        tell thePopup
            click
            if the value of thePopup begins with "F1" then
                key code {126, 36}
            else
                key code {125, 36}
            end if
        end tell
    end tell
end tell

quit application "System Preferences"

It is based on this answer: https://apple.stackexchange.com/a/316511

Thanks!

jkbrzt commented 4 years ago

I see! It would be awesome if it was possible to support both Touch Bar and non-Touch Bar MacBooks at the same time.