日々適当

hibitekitou

WakeOnLanがAppleScriptに対応したよ

mac |2005-11-26
ネットワーク越しにスリープしたマシンを起こす事の出来るソフトにWakeOnLanってのがありますが、バージョン0.5.4にてついにAppleScriptから制御可能になりました。
といっても、

wakeup unicode text

って命令を送れるだけですけど、

tell application "WakeOnLan"
wakeup "IPアドレスかマシン名"
end tell

を実行させるとネットワーク越しのマシンを起こすとこが出来るようになるってのは大きいです。

例えば簡単な所だと

--------------------------
tell application "WakeOnLan"
wakeup "マシン名"
quit
end tell

(ここにスリープから目覚めるまでのディレイを入れてやる必要はあると思う)

mount volume "afp://マシン名/共有領域名" as user name "ユーザ名" with password "ユーザのパスワード"
--------------------------

を実行してやれば、ネットワーク越しの普段はスリープさせる設定のマシンのボリュームをマウントさせることが出来るわけですから。

これで、AirMac越しのマシンも起こせたら最高なんだけどなぁ…

追記
そんなわけで、以下をスクリプトメニューに登録してみた。でもまだ安定して動かない(このスクリプトが)。ってことで、ちょっと消しとく。一応動く、ってことで、消すのは解除。ま、一応、動くだけ。
それにしても、AppleScriptでログイン系を安全にするにはどうすればいいんでしょ?

property mIP : "xxx.xxx.xxx.xxx" --スリープしているマシンのIPアドレス
property mURI : "afp://xxx.xxx.xxx.xxx/yyy" --マウントしようとする共有領域へのパス
property userName : "zzz" --マウント時に使用するユーザ名
property userPss : "pass" --マウント時に使用するユーザのパスワード

on run
set i to 1

repeat
set mFlag to checkMac()
if mFlag is equal to "TRUE" then
mountVolume()
exit repeat
else
tell application "WakeOnLan"
wakeup mIP
quit
end tell
end if

set i to i + 1

if i is equal to 5 then
display dialog "time out"
exit repeat
end if
delay 10
end repeat
end run

--マシンのチェック
on checkMac()
--netstat でネットワークを確認
do shell script "netstat -rn"
set netstatResult to result
set netstatResultList to paragraphs of netstatResult

set originalDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
set i to 6
set mFlag to "FALSE"

--対象マシンがnetstatで得られた結果に存在するかチェック
repeat
set checkParagraph to item i of netstatResultList
set checkWord to item 1 of (text items of checkParagraph)
if checkWord is equal to "Internet6:" then
exit repeat
else if checkWord is equal to mIP then --対象マシンのIPアドレス指定
set mFlag to "TRUE"
exit repeat
end if
set i to i + 1
end repeat

set AppleScript's text item delimiters to originalDelim

return mFlag --mFlagを返す
end checkMac

--マウント処理
on mountVolume()
mount volume mURI as user name userName with password userPss
return
end mountVolume
コメント ( 0 )|Trackback ( )
  ・