Subscribe to
Posts
Comments
NSLog(); Header Image

No AppleScript ‘Mute’?

I looked quickly and could not find an AppleScript command to mute the sound on my Mac. Instead, I've had to get by with tell appplication "System Events" to set volume 0. I do this via cron at 10pm. At 7am, I reset the volume to 3.5 (half volume). Being able to mute and unmute via AppleScript (i.e. osascript in my cron file) is desired simply because the previous volume setting is preserved and restored when you unmute.

Has anyone seen a mute command in AppleScript? Have I simply missed it?

15 Responses to "No AppleScript ‘Mute’?"

  1. Couldn't you use the "get volume settings" and store it in a variable?

  2. For a cron job? It's really not worth that.

  3. I couldn't find a "mute" command, but this works if you have System Prefs running:

    tell application "System Events"

    tell process "System Preferences"

    click checkbox "Mute" of first group of window "Sound"

    end tell

    end tell

  4. As I've said, Samuel, this is in a cron job via osascript. Any more than one line is "too much," particularly when I spend 95% of my time at "3.5" volume. I'm merely talking about the lack of a good "mute" option in other situations when it may be handy without reverting to work-arounds.

  5. Really worth what? 6 lines of code?

    Are you running Tiger? This might work with Panther as well, haven't checked though.

    set myVolume to get volume settings
    if output muted of myVolume is false then
        set volume with output muted
    else
        set volume without output muted
    end if
    1. Your reply was in 2005. Now is 2014. I am running on Mavericks, and you just posted what I needed the most! Thank you! I have been trying to get the mute flags like mad! haha.

    2. Thanks for this, works in Mavericks great. Needed this because the old xGestures 'toggle mute' function stopped working correctly and now I just have it run this applescript instead. Thank you for the great script tip.

  6. Based on what Samuel said, what's wrong with just using tell application "System Events" to set volume with output muted at 10pm and tell application "System Events" to set volume without output muted at 7am? He obviously found the setting you were looking for; you just have to package it up correctly.

  7. Yeah, that'll work. I read his answer quickly and thought he'd just wrapped the two set volume commands inside an if statement. My bad.

  8. I misread you as well, Erik. Sorry if I sounded a bit harsh. 😉 I thought your cron job were running a .scpt file via osascript.

    Bo's solution is of course the way to go in your case.

  9. How about osascript -e 'set volume output muted true' and osascript -e 'set volume output muted false'?

  10. Awesome PMcM. I used that for an automator script to mute the sound before a task and then unmute it.

    Thanks

  11. [...] thanks to the commenters on Erik Barzeski’s blog for the AppleScript and Bernhard Baehr for sleepwatcher. You can use similar tricks to get rid of [...]

  12. FYI, under Lion the above script no longer works but simply modifying it to what is below does:

    tell application "System Events"

    tell process "System Preferences"

    click checkbox "Mute" of window "Sound"

    end tell

    end tell

  13. My two scripts - which work in Lion just fine - are:

    .script-night.app:

    tell application "System Events"
        if exists (process "ScreenSaverEngine") then
            tell application "System Events" to set volume with output muted
        end if
    end tell

    .script-morning.app:

    tell application "System Events" to set volume without output muted