Skip to content

Instantly share code, notes, and snippets.

@jghankins
Created July 9, 2025 11:51
Show Gist options
  • Select an option

  • Save jghankins/a6c607179e16dae6a36c1b51fa7b01f4 to your computer and use it in GitHub Desktop.

Select an option

Save jghankins/a6c607179e16dae6a36c1b51fa7b01f4 to your computer and use it in GitHub Desktop.
Toggle Menu Bar
#!/usr/bin/env node
// Required parameters:
// @raycast.schemaVersion 1
// @raycast.title Toggle Menu Bar
// @raycast.mode compact
// @raycast.packageName System
// Optional parameters:
// @raycast.icon 🔄
// @raycast.description Toggle the visibility of the Mac menu bar
// @raycast.author Jim Hankins
// @raycast.authorURL https://cloudbedrock.com
const { execSync } = require('child_process');
try {
// Use AppleScript to toggle menu bar auto-hide
const script = `
tell application "System Events"
tell dock preferences
set currentState to autohide menu bar
set autohide menu bar to not currentState
if autohide menu bar then
return "Menu bar will auto-hide"
else
return "Menu bar will always show"
end if
end tell
end tell
`;
const result = execSync(`osascript -e '${script}'`, { encoding: 'utf8' }).trim();
console.log(result);
} catch (error) {
console.error('Error toggling menu bar:', error.message);
// Fallback method using defaults
try {
const currentState = execSync('defaults read com.apple.dock autohide-menu-bar', { encoding: 'utf8' }).trim();
if (currentState === '1') {
execSync('defaults write com.apple.dock autohide-menu-bar -bool false');
console.log('Menu bar set to always show');
} else {
execSync('defaults write com.apple.dock autohide-menu-bar -bool true');
console.log('Menu bar set to auto-hide');
}
execSync('killall Dock');
} catch (fallbackError) {
console.error('Fallback method also failed:', fallbackError.message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment