Skip to main content
Glama

notifications_toggle_do_not_disturb

Toggle Do Not Disturb mode on macOS to silence notifications using AppleScript automation.

Instructions

[Notification management] Toggle Do Not Disturb mode using keyboard shortcut

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • AppleScript implementation that executes the tool logic by sending a specific keyboard shortcut (Cmd+Opt+Ctrl+Z) to toggle Do Not Disturb mode in System Events.
    { name: "toggle_do_not_disturb", description: "Toggle Do Not Disturb mode using keyboard shortcut", script: ` try tell application "System Events" keystroke "z" using {control down, option down, command down} end tell return "Toggled Do Not Disturb mode" on error errMsg return "Failed to toggle Do Not Disturb: " & errMsg end try `, },
  • Registers all tools in the listTools handler, constructing the tool name as '{category}_{script}', resulting in 'notifications_toggle_do_not_disturb'.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: this.categories.flatMap((category) => category.scripts.map((script) => ({ name: `${category.name}_${script.name}`, // Changed from dot to underscore description: `[${category.description}] ${script.description}`, inputSchema: script.schema || { type: "object", properties: {}, }, })), ), }));
  • Executes the specific script for the tool by calling executeScript on the script content from the matching category and script.
    const scriptContent = typeof script.script === "function" ? script.script(request.params.arguments) : script.script;
  • Helper function that executes the AppleScript code using osascript, handling execution and errors.
    private async executeScript(script: string): Promise<string> { // Log script execution (truncate long scripts for readability) const scriptPreview = script.length > 100 ? script.substring(0, 100) + "..." : script; this.log("debug", "Executing AppleScript", { scriptPreview }); try { const startTime = Date.now(); const { stdout } = await execAsync( `osascript -e '${script.replace(/'/g, "'\"'\"'")}'`, ); const executionTime = Date.now() - startTime; this.log("debug", "AppleScript executed successfully", { executionTimeMs: executionTime, outputLength: stdout.length }); return stdout.trim(); } catch (error) { // Properly type check the error object let errorMessage = "Unknown error occurred"; if (error && typeof error === "object") { if ("message" in error && typeof error.message === "string") { errorMessage = error.message; } else if (error instanceof Error) { errorMessage = error.message; } } else if (typeof error === "string") { errorMessage = error; } this.log("error", "AppleScript execution failed", { error: errorMessage, scriptPreview }); throw new Error(`AppleScript execution failed: ${errorMessage}`); } }
  • src/index.ts:6-29 (registration)
    Imports and registers the notifications category containing the toggle_do_not_disturb script.
    import { notificationsCategory } from "./categories/notifications.js"; import { itermCategory } from "./categories/iterm.js"; import { mailCategory } from "./categories/mail.js"; import { pagesCategory } from "./categories/pages.js"; import { shortcutsCategory } from "./categories/shortcuts.js"; import { messagesCategory } from "./categories/messages.js"; import { notesCategory } from "./categories/notes.js"; const server = new AppleScriptFramework({ name: "applescript-server", version: "1.0.4", debug: false, }); // Log startup information using stderr (server isn't connected yet) console.error(`[INFO] Starting AppleScript MCP server - PID: ${process.pid}`); // Add all categories console.error("[INFO] Registering categories..."); server.addCategory(systemCategory); server.addCategory(calendarCategory); server.addCategory(finderCategory); server.addCategory(clipboardCategory); server.addCategory(notificationsCategory);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/joshrutkowski/applescript-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server