2010/07/11

關閉MAC OS X的開機聲

不太喜歡MAC OS 進入系統時發出的開機聲,所以上網找了靜音的方法
方法一是可以安裝StartupSound.prefPane這套免費軟體,有圖形介面可以簡單的設定
不過我用了shell script的方式來做,是在國外論壇找到的方法,目前我使用上也一切正常

節錄出結論如下:

基本上概念是關機時將系統靜音,開機時再恢復,用的是下列兩個script語法,設定分別在關機、開機時執行
osascript -e 'set volume with output muted'
osascript -e 'set volume without output muted'




怕連結失效,這邊貼出koit分享的Step by Step

1. Login as administrator and open a terminal window

2. Create scriptfile for muting
sudo nano /path/to/mute-on.sh

3. Enter this as content, when done press control+O to save and control+X to exit:
#!/bin/bash
osascript -e 'set volume with output muted'

4. Create scriptfile for unmuting
sudo nano /path/to/mute-off.sh

5. Enter this as content, when done press control+O to save and control+X to exit:
#!/bin/bash
osascript -e 'set volume without output muted'

6. Make both files executable:
chmod u+x /path/to/mute-on.sh
chmod u+x /path/to/mute-off.sh

7. Check if any hooks already exist (these will be overwritten, so make sure it is OK for you)
sudo defaults read com.apple.loginwindow LoginHook
sudo defaults read com.apple.loginwindow LogoutHook

8. Add hooks for muting
sudo defaults write com.apple.loginwindow LogoutHook /path/to/mute-on.sh
sudo defaults write com.apple.loginwindow LoginHook /path/to/mute-off.sh

Notes:
- /path/to/ is the location of the scripts, I used /Library/Scripts/
- you can skip the unmuting loginhook (i.e. each logout will silence your machine), but I like it this way because I always have sound available exactly at the volume level I set last time
- root has to be the owner of the script files - running an editor from command line with sudo is the easiest way to achieve that (otherwise you need to chown)
- to delete the hooks, use the following:
sudo defaults delete com.apple.loginwindow LoginHook
sudo defaults delete com.apple.loginwindow LogoutHook

沒有留言: