LoginSignup
24
24

More than 5 years have passed since last update.

Mac OS XのNotificationに定時を教えてもらう

Last updated at Posted at 2014-06-26

なるべくなら定時に帰りたい!
最近は気付いたら定時過ぎてる!!
そうだ、画面に定時だって表示しよう!!

zshのプロンプトに定時を教えてもらう

zsh使ってないし常にコンソール開いてる訳じゃない!!!

Notification Centerとlaunchd使おう

Mac OS X 1.8以降にはNotification Center(通知センター)という機能があります。
昔はGrowlとか使って出してたアレです。画面の隅に、アプリケーションからのお知らせを出すことができます。

launchdはMac OSにおけるプロセス制御のためのデーモンらしいです。全てのプロセスはlaunchdの子プロセスになるらしい。へー。

一定時間ごとにプログラムを実行する、指定時刻にプログラムを実行する、などといったことが行えます。高機能crontabみたいな感じ?

表示させる

1. terminal-notifierをインストールする

terminal-notifierは、引数に与えられたメッセージをNotification Centerに表示してくれるだけのシンプルなツールです。

サクッと入れちゃいます。

$ [sudo] gem install terminal-notifier

or

$ brew install terminal-notifier

インストール先のフルパスを調べておきましょう。後で使います。

$ which terminal-notifier

2. launchd用のplistファイルを作る

以下のファイルを適当に編集して、~/Library/LaunchAgents/に保存してください。
月〜金曜日の18:00に通知が出るようにしています。

~/Library/LaunchAgents/定時.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>net.kikuchy.teiji</string>
    <key>LimitLoadToSessionType</key>
    <string>Aqua</string>
    <key>ProgramArguments</key>
    <array>
        <string> (terminal-notifierのフルパス) </string>
        <string>-title</string>
        <string>定時だ帰るぞ!</string>
        <string>-message</string>
        <string>そろそろ定時</string>
    </array>
    <key>StartCalendarInterval</key>
    <array>
        <dict>
            <key>Minute</key>
            <integer>0</integer>
            <key>Hour</key>
            <integer>18</integer>
            <key>Weekday</key>
            <integer>1</integer>
        </dict>
        <dict>
            <key>Minute</key>
            <integer>0</integer>
            <key>Hour</key>
            <integer>18</integer>
            <key>Weekday</key>
            <integer>2</integer>
        </dict>
        <dict>
            <key>Minute</key>
            <integer>0</integer>
            <key>Hour</key>
            <integer>18</integer>
            <key>Weekday</key>
            <integer>3</integer>
        </dict>
        <dict>
            <key>Minute</key>
            <integer>0</integer>
            <key>Hour</key>
            <integer>18</integer>
            <key>Weekday</key>
            <integer>4</integer>
        </dict>
        <dict>
            <key>Minute</key>
            <integer>0</integer>
            <key>Hour</key>
            <integer>18</integer>
            <key>Weekday</key>
            <integer>5</integer>
        </dict>
    </array>
</dict>
</plist>

3. launchdに登録する

今作ったplistファイルをlaunchdに読みこませます。

$ launchctl load ~/Library/LaunchAgents/定時.plist

これで準備完了です。
18:00になると、こんな感じになります。

定時になると

さいごに

これで定時に帰れたら苦労しない

24
24
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
24
24