No AppleScript ‘Mute’?
Posted June 26th, 2005 @ 12:04pm by Erik J. Barzeski
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?
Posted 26 Jun 2005 at 12:22pm #
Couldn't you use the "get volume settings" and store it in a variable?
Posted 26 Jun 2005 at 12:49pm #
For a cron job? It's really not worth that.
Posted 26 Jun 2005 at 1:53pm #
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
Posted 26 Jun 2005 at 4:51pm #
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.
Posted 26 Jun 2005 at 4:10pm #
Really worth what? 6 lines of code?
Are you running Tiger? This might work with Panther as well, haven't checked though.
Posted 13 Jan 2014 at 5:14am #
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.
Posted 24 Feb 2015 at 1:25pm #
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.
Posted 26 Jun 2005 at 5:41pm #
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.
Posted 26 Jun 2005 at 6:03pm #
Yeah, that'll work. I read his answer quickly and thought he'd just wrapped the two
set volume
commands inside anif
statement. My bad.Posted 27 Jun 2005 at 1:35am #
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.
Posted 13 Jul 2005 at 10:51am #
How about
osascript -e 'set volume output muted true'
andosascript -e 'set volume output muted false'
?Posted 01 Jun 2008 at 9:59pm #
Awesome PMcM. I used that for an automator script to mute the sound before a task and then unmute it.
Thanks
Posted 17 Feb 2010 at 9:16am #
[...] 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 [...]
Posted 30 Sep 2011 at 7:36am #
FYI, under Lion the above script no longer works but simply modifying it to what is below does:
Posted 02 Oct 2011 at 1:13pm #
My two scripts - which work in Lion just fine - are:
.script-night.app:
.script-morning.app: