I want to run a script when I shutdown or restart my iMac, running Snow Leopard.

I read somewhere that one could use the /etc/rc.shutdown.local for this, but it is not working for me.

For example, I put the following lines on it:

#!/bin/sh
/usr/bin/osascript -e "set volume with output muted"

If I run:

source /etc/rc.shutdown.local

it does indeed mute the sound. However, if I have the sound on and make a restart of the OS, the sound will still be on. Which I guess it means the script was not called.

Any ideas?

UPDATE: It is actually working now. I think it's just because the correct name is rc.local.shutdown and not rc.shutdown.local.

link|improve this question
This seems a little bit backwards to me. Why don't you just run the muting script at startup? Keep in mind that the boot chime is no longer mutable on current-generation hardware. – NReilingh Mar 4 '11 at 2:48
Please add an answer to your own question if you figured it out yourself, and click the checkmark next to it. This will mark this question resolved. – Daniel Beck Mar 5 '11 at 16:11
feedback

3 Answers

up vote 1 down vote accepted

It is actually working now. I think it's just because the correct name is rc.local.shutdown and not rc.shutdown.local.

link|improve this answer
feedback

Use the following script:

#!/usr/bin/env bash
trap 'osascript -e "say \"hello\""' TERM
while true; do
    sleep 10
done

Start it via cron or launchd, whichever you prefer.

Try killing it using kill pid, which pid being its process ID you learn from ps ax.


I don't want to shut down right now to test it propertly, but it should work.

link|improve this answer
Shouldn't your osascript line be "set volume with output muted" instead of a say command? – NReilingh Mar 4 '11 at 2:49
@NReilingh True. I tested the trap using say and didn't bother to change. – Daniel Beck Mar 4 '11 at 2:51
feedback

I'll start off by saying I'm a noob with AppleScript. So for the benefit of other folks starting off as well - I'm posting the following which is a minor variation of what the author put in.

#!/bin/sh
/usr/bin/osascript -e "set volume 0.5"
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.