Keyboard shortcut to sleep a Mac's touchbar
Solution 1:
tl;dr: You can get a shortcut/script/service to revert Touch Bar to work as normal F keys. This is very close to a normal keyboard, with backlight on, in the night.
I used this answer https://stackoverflow.com/a/18752770/10063119 to get the code from the Automator’s “watch me do“.
Open Automator, choose a new “workflow” and keep System Preferences in the dock. Hit the red record button and use System Preferences to disable the fancy Touch Bar and set it to the normal F keys.
Select all steps in the workflow and paste in Script Editor app. Then you can edit it to your need, bind it to keyboard shortcut in System Preferences → Keyboard → Shortcuts. You can also do some modifications to see which mode is active and then decide what action to take. Set the scope of shortcut to “all apps“.
- How do I assign a keyboard shortcut to an AppleScript I wrote?
The (unverified, I don't have that model) code is given. You can check and modify as required.
- http://osxdaily.com/2018/08/30/disable-touch-bar-macbook-pro/
-- Click “System Preferences” in the Dock.
delay 1
set timeoutSeconds to 2.0
set uiScript to "click UI Element \"System Preferences\" of list 1 of application process \"Dock\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the “Keyboard” button.
delay 1
set timeoutSeconds to 2.0
set uiScript to "click UI Element \"Keyboard\" of scroll area 1 of window \"System Preferences\" of application process \"System Preferences\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the “Keyboard” tab.
delay 1
set timeoutSeconds to 2.0
set uiScript to "click radio button \"Keyboard\" of tab group 1 of window \"Keyboard\" of application process \"System Preferences\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Make a selection from the popupbutton.
delay 1
set timeoutSeconds to 2.0
set uiScript to "click pop up button 1 of tab group 1 of window \"Keyboard\" of application process \"System Preferences\""
my doWithTimeout(uiScript, timeoutSeconds)
-- 10 secs
delay 1
set timeoutSeconds to 2.0
set uiScript to "click menu item \"Expanded Control Strip\" of menu 1 of pop up button 2 of tab group 1 of window \"Keyboard\" of application process \"System Preferences\""
my doWithTimeout(uiScript, timeoutSeconds)
- Click the “System Preferences” menu.
delay 1
set timeoutSeconds to 2.000000
set uiScript to "click menu bar item \"System Preferences\" of menu bar 1 of application process \"System Preferences\""
my doWithTimeout( uiScript, timeoutSeconds )
-- Quit System Preferences
delay 1
set timeoutSeconds to 2.000000
set uiScript to "click menu item \"Quit System Preferences\" of menu 1 of menu bar item \"System Preferences\" of menu bar 1 of application process \"System Preferences\""
my doWithTimeout( uiScript, timeoutSeconds )
on doWithTimeout(uiScript, timeoutSeconds)
set endDate to (current date) + timeoutSeconds
repeat
try
run script "tell application \"System Events\"
" & uiScript & "
end tell"
exit repeat
on error errorMessage
if ((current date) > endDate) then
error "Can not " & uiScript
end if
end try
end repeat
end doWithTimeout