LoginSignup
4
12

More than 5 years have passed since last update.

Macにて,スリープ解除時にWindowsの起動音で迎えてもらう

Last updated at Posted at 2017-01-08

目次

1.概要
2.環境
3.スリープ解除を検知する
4.音源を用意する
5.音源再生をスリープ解除のスクリプトに組み込む
6.まとめ

概要

Macのスリープを解除した時に,好きなWindowsの起動音で迎えてくれるスクリプトを作成します.

環境

macOS Sierra(version: 10.12.2)
AppleScript

スリープ解除を検知する

下記のサイトを参考に,Macのスリープ解除を検知するプログラムを書きました.
ASH Planning: スリープの解除を検出

SleepDetect.app
property theRes : ""

on run
    set theRes to do shell script "grep -i 'wake' /var/log/system.log"
end run

on idle
    set tmp to do shell script "grep -i 'wake' /var/log/system.log"
    if tmp is not theRes then
        set theRes to tmp
        display dialog "スリープを解除しました"
    end if
    return 2
end idle

このスクリプトをアプリケーションとして保存する際に,「実行終了後にアプリケーションを終了しない」にチェックを入れ,常駐アプリケーションとして起動させます.

上記のコードは簡潔に言いますと,読み取ったシステムのログの変化から,Macの起動を検出し,起動を検出した時にダイアログを表示するというものです.

音源を用意する

下記のサイトにて,Windowsの起動音が配布されてるのでmp3でダウンロードし, aiffに変換します.
Windows Startsounds
筆者はWindowsXPの音源をダウンロードしました.

音源再生をスリープ解除のスクリプトに組み込む

Macのターミナルでは,aiff音源を再生するafplayコマンドがあるのでそれを使います.

$ afplay <音源を置いたディレクトリ>/winxp.aif

ターミナルで上のコマンドを打つと,音源が再生されるのが分かるかと思います.

それでは,スリープ解除時に音源を再生するスクリプトを書いて行きたいと思います.
...と言っても,先ほどのコードのdisplay dialogの部分を上記のコマンドに変えるだけです.

完成したコード(アプリケーション)は以下のようになります.

WinAlert.app
property theRes : ""

on run
    set theRes to do shell script "grep -i 'wake' /var/log/system.log"
end run

on idle
    set tmp to do shell script "grep -i 'wake' /var/log/system.log"
    if tmp is not theRes then
        set theRes to tmp
        do shell script "afplay /Users/<ユーザ名>/Desktop/mymusic/winxp.aif"
    end if
    return 2
end idle

まとめ

Macのスリープを解除した時にWindowsの起動音で迎えてくれるアプリケーションができました.
他の音で試したり,「今日も頑張ろう!」みたいなボイスを入れても面白いかもしれないですね.

4
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
12