LoginSignup
1
1

More than 5 years have passed since last update.

AppleScriptでntpdate

Last updated at Posted at 2017-03-06

自宅にNTP Stratum 1なサーバが設置できたので、Macの時間をntpでAppleScriptで設定する方法を調べてみました。

通常はntpdateなどを使うのですが、これだと管理者権限が必要になるので、システム環境設定の「日付と時刻」の「日付と時刻」パネルを開いたときにntpdateを実行するようなので、これをAppleScriptでシュミュレーションしてみました。


tell application "System Preferences"
    activate
    reveal anchor "DateTimePref" of pane id "com.apple.preference.datetime"
end tell
tell application "System Events"
    tell process "System Preferences"
    end tell
end tell
quit application "System Preferences"

雪豹で確認しています。新しいMac OS Xでは試していません。

あ、事前に「日付と時刻を自動設定」にチェックを入れてサーバを設定しておく必要がありました。on/offはコマンドでもできるようです。

bash-3.2$ systemsetup -setusingnetworktime on 
setUsingNetworkTime: On

Mac OS X 10.5で実行したかったのだが、動かない。。。

下記は10.5でも実行できました。事前にパネルを開いておけば、同じように動くようです。

tell application "System Preferences"
    activate
    set current pane to pane "com.apple.preference.datetime"
end tell
quit application "System Preferences"

なぜこれが必要だったかというと、FMラジオをエアチェックするMac OS Xアプリ(猫のお留守番)で録音開始時刻をずれないようにしたかったからです。

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