Skip to content

Instantly share code, notes, and snippets.

@thomasstep
Created June 26, 2025 12:23
Show Gist options
  • Save thomasstep/32f45acbe40f65bb01b4a10f2ab8ee7f to your computer and use it in GitHub Desktop.
Save thomasstep/32f45acbe40f65bb01b4a10f2ab8ee7f to your computer and use it in GitHub Desktop.
Organize Mac Dock

To run this, simply run ./organizeDock.js in a Terminal while in the directory that this script is saved.

#!/usr/bin/env osascript -l JavaScript
const app = Application.currentApplication();
app.includeStandardAdditions = true;
function run(input, parameters) {
const appsToRemove = [
'App Store',
'Pages',
'Notes',
];
const sysEvents = Application('System Events');
appsToRemove.forEach((app) => {
try {
sysEvents.processes['Dock'].lists[0].uiElements.byName(app).actions['AXShowMenu'].perform();
delay(0.5);
sysEvents.processes['Dock'].lists[0].uiElements.byName(app).menus[0].menuItems['Options'].click();
delay(0.5);
sysEvents.processes['Dock'].lists[0].uiElements.byName(app).menus[0].menuItems['Options'].menus[0].menuItems['Remove from Dock'].click();
delay(0.5);
} catch (err) {
console.log(`Error removing ${app}`);
console.log(err);
}
});
const appsToOpen = [
'Slack',
'Activity Monitor',
];
appsToOpen.forEach((app) => {
try {
Application(app).activate();
console.log(`Opened ${app}`);
} catch (err) {
console.log(`Error opening ${app}`);
console.log(err);
}
});
return input;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment