1

My environment: Sonoma 14.2.1 on MacBook Pro 14 (2021).

What I wnat do to is:

(1) If I press the F6 key,

(2) then DND is on, and at the same time the menu bar auto hide is on.

(3) If I again press F6,

(4) then DND and menu bar auto hide are off.

(5) This have to work both in desktop and full screen mode.

What I have tried are:

(a). As a partial solution, I opened AppleScript and typed:

tell application "System Events"
    if autohide menu bar of dock preferences then
        set autohide menu bar of dock preferences to false
    else
        set autohide menu bar of dock preferences to true
    end if
end tell

But (a) is not good because this works only in desktop; that is, this does not work in the full screen mode.

(b). Another partial solution I tried is to use the Automator which runs bin/bash contaning the commands like:

(...some 'if' statements...)
defaults write -g AppleMenuBarVisibleInFullscreen -bool false
(...and 'delete' in the place of 'write'...)

But this didn't make any change to my menu bar.

So what can I do now? Thanks to any helps and suggestions.

1
  • i'm looking for a list or documentation on the names of the panes or menus, but no luck - those I could find didnt work for me. can you share a link or anything? I'm trying to write a script that toggles the Fn / standard Function keys on off and then open some app. For example a script that launches the an IDE but before that toggles the settings of Fn / Function keys to be standard function keys. I also found a bunch of scripts but none worked for me (MacOS Sonoma) Highly appreciated!!
    – jack smith
    Commented Jan 24 at 18:16

1 Answer 1

1

The following AppleScript automates the toggling between Always and Never modes for automatically hiding the menu bar on macOS 14.5 (Sonoma):

tell application "System Settings"
    reveal pane id "com.apple.ControlCenter-Settings.extension"
end tell

delay 0.4

tell application "System Events"
    tell window 1 of application process "System Settings"
        tell pop up button "Automatically hide and show the menu bar" of group 9 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1
            click
            if value = "Never" then
                click menu item "Always" of menu 1
            else
                click menu item "Never" of menu 1
            end if
            
        end tell
    end tell
end tell

delay 0.4

tell application "System Settings" to quit

Adding Do Not Disturb (DND) Toggle

To toggle Do Not Disturb (DND) at the same time, create an Apple Shortcut and configure it as a Quick Action. Follow these steps:

  1. Create a new shortcut and add the following actions.
  2. In the shortcut's Details section:
    • Set it to Use as Quick Action.
    • Assign F6 in the Run with: section.

enter image description here

Configuring the Keyboard Shortcut

Before assigning the F6 key to your shortcut, you need to disable its current functionality:

  1. Open System Settings on your Mac.
  2. Navigate to Keyboard > Keyboard Shortcuts.
  3. Select Mission Control.
  4. Turn off any actions currently assigned to the F6 key.

Once this is done, you can assign the F6 key to your new shortcut to toggle both the menu bar visibility and Do Not Disturb mode. enter image description here

Notice

You will probably need to grant accessibility access to the Shortcuts app to perform these actions. To do this:

  1. Open System Settings.
  2. Go to Privacy & Security > Accessibility.
  3. Ensure that Shortcuts is enabled in the list of apps allowed to control your Mac.
1
  • Nice work. Could you also add some information on how the OP can link the script to pressing F6, as requested? Commented Jun 28 at 10:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .