How to Automate Menu Bar Icons with AppleScript
For power users, clicking is slow. Learn how to control SaneBar programmatically using AppleScript, Raycast, Alfred, or Shortcuts.
SaneBar is built with automation in mind. Unlike other menu bar managers that rely on private APIs or accessibility hacks, SaneBar exposes a clean AppleScript dictionary.
Basic Commands
You can run these commands from Terminal (using osascript) or the Script Editor app.
tell application "SaneBar" to toggle
-- Explicitly show hidden items
tell application "SaneBar" to show hidden
-- Explicitly hide items
tell application "SaneBar" to hide items
Move Icons Relative to Each Other
Use list icon zones to copy stable icon identifiers, then reorder within the same visible, hidden, or always-hidden section.
tell application "SaneBar" to list icon zones
-- Move one icon immediately before another icon in the same section
tell application "SaneBar" to move icon before "SOURCE_ID" target icon "TARGET_ID"
-- Move one icon immediately after another icon in the same section
tell application "SaneBar" to move icon after "SOURCE_ID" target icon "TARGET_ID"
Use with Raycast or Alfred
You can create a script command in Raycast or a Workflow in Alfred to toggle your menu bar without lifting your hands from the keyboard.
Raycast Setup
- Create a new Script Command.
- Select "AppleScript" as the language.
- Paste
tell application "SaneBar" to toggle. - Assign an alias (e.g., "mb").
Advanced: Context-Aware Logic
Since you can query the state, you can build complex logic. For example, "If I launch Zoom, ensure menu bar icons are hidden to avoid distractions."
if (name of first application process whose frontmost is true) is "zoom.us" then
tell application "SaneBar" to hide items
end if
end tell
Get the Hackable Menu Bar Manager
SaneBar gives you full control. Script it, style it, lock it.
Download Free