Mute Sound Temporarily

If you have iTunes blasting through your external speakers and the phone rings, this miniscule script is the answer (at least in OS X. Otherwise use Jon’s Commands)

set volume with output muted
display dialog "Restore volume setting" buttons {"Yes"} default button 1 -- the script just sits there until you answer
if button returned of result = "Yes" then set volume without output muted

Hi Adam

Anyway to adjust this script a little so that it runs on Shutdown, turning the volume down to a respectable level (say half volume)? I am tired of turning on the Mac and having it boom out its startup chord at full volume…it sometimes even wakes our baby who sleeps in the next room!

Matthew

Save this a application (Stay Open)
Leave it running. It will just sit there doing nothing until its quit.
When its quit if the volume is more than 50% it will set the volume to 50%

on quit
	tell application "System Events"
		set getSound to (get volume settings) as list
		
		set ShutdownLevel to 50
		set Theoutput to item 1 of getSound
		if Theoutput > ShutdownLevel then
			set volume output volume ShutdownLevel
		end if
		
	end tell
end quit

ah hold on a sec. the app works but does not quit…

be back…

I should be able to tell the app to quit me.

but I never seem to be able to get it to work well…

any way this works. just make sure the meapp is set to the same name as the name you give the app
put \ befor any spaces.

global meapp
on quit
	tell application "System Events"
		set meapp to "Sound\\ down.app"
		
		set getSound to (get volume settings) as list
		
		set ShutdownLevel to 50
		set Theoutput to item 1 of getSound
		if Theoutput > ShutdownLevel then
			set volume output volume ShutdownLevel
		end if
		
	end tell
	quit_()
end quit

on quit_()
	
	set thePID to do shell script "ps acx |grep -i " & quoted form of meapp & " | awk {'print $1'}" as string
	do shell script "kill " & thePID
	
end quit_

Hi matt,
Save this as a stay-open application, and get it to open at login if you want restore the volume after starting up:

property lowVolume : 25
property fullVolume : 75

on run
	set volume output volume fullVolume
end run

on quit
	set fullVolume to output volume of (get volume settings)
	set volume output volume lowVolume
	continue quit
end quit

(I haven’t tried/tested it.)

I’ve used ‘tell me to quit’ successfully in stay open scripts…

Might be worth a try.

Peter B.


Thanks.

But I tried it every way but L…

Hi Mark, Querty Denzel et al

Thanks for your advice and suggestions re this problem. I am testing Querty Denzel’s suggestion as I didn’t know how to deal with the meapp thing! I’m a newbie at AppleScript.

I will let you know if it does the job.

Regards

Matthew

A key item in an ‘on quit’ handler is the ‘continue quit’. You’ve trapped the original quit command to do stuff and interrrupted that process - you have to restore it with the last line: ‘continue quit’. Qwerty has it right.

Hi all

The script (Querty Denzel’s version) does exactly what I want, however I’d rather that it wasn’t an app that stayed open all the time. Is there any way to run it at shutdown? - like under OS9 where there was a Shutdown Items folder.

Matthew

For those who are too lazy:

I wrote an Application upon this.

It’s called “Psst” (Universal Binary) ” http://macupdate.com/info.php/id/16780

It’s a invisible background app and uses absolutely no CPU !!!

Matt1710 worried about a stay-open app. Qwerty’s application uses a twitch of cpu to do “on run” then does nothing but occupy a tiny bit of memory as a compiled script app in memory until System Events tells it to quit as part of the logout process (which quits all running apps). If you check in the Activity Monitor while you’re working, you’ll see it is doing nothing.

Thanks Adam for the continue quit bit.
I always new there was a on quit handler but never looked it up. Doh

:slight_smile:

Hi

I’m not so much concerned with the amount of memory that the app uses - I may be being fussy about this but what I don’t like is having that AppleScript icon in the dock all day long…

If there’s a way to remove that it’d be cool…

Matthew

It’s not being fussy. Try this method to hide the icon.

Hi Querty Denzel

Awesome - that’s just what I needed.

Matthew