2010年12月2日木曜日

realmlist.wtfを入れ替えるAppleScript

Macで出来るMMORPG「World of Warcraft

複数のサーバで遊ぶために、realmlist.wtf を簡単に入れ替えるスクリプトを書いてみました。
実行するとこんな感じになります。
script.KfPIO6cgKAVe.jpg

--サーバ選択ボタンを表示します。
display dialog "接続先を指定してください。" buttons {"サーバ1", "サーバ2", "リストを編集"} default button 1
set WOWSERVERS to button returned of result

--「サーバ1」ボタンを押すとrealmlist_01.wtf(あらかじめ用意しておく)の内容をrealmlist.wtfに上書きします。
if WOWSERVERS is "サーバ1" then
set cmd to "/Applications/World\\ of\\ Warcraft/Data/enUS/"
do shell script "cp " & cmd & "realmlist_01.wtf " & cmd & "realmlist.wtf"

--「サーバ2」ボタンを押すとrealmlist_02.wtf(あらかじめ用意しておく)の内容をrealmlist.wtfに上書きします。
else if WOWSERVERS is "サーバ2" then
set cmd to "/Applications/World\\ of\\ Warcraft/Data/enUS/"
do shell script "cp " & cmd & "realmlist_02.wtf " & cmd & "realmlist.wtf"

--「リストを編集」ボタンを押すとrealmlist.wtfをテキストエディットで開きます。
else if WOWSERVERS is "リストを編集" then
do shell script "open -a /Applications/TextEdit.app/ /Applications/World\\ of\\ Warcraft/Data/enUS/realmlist.wtf"

end if

--ゲームの開始ボタンを表示します。
tell application "System Events"
activate
display dialog "ゲームを始めますか?" buttons {"キャッシュを消去して開始", "開始", "今はしない"} default button 1
set WOWCACHE to button returned of result

--「キャッシュを消去して開始」ボタンを押すとキャッシュを消してからゲームが始まります。
if WOWCACHE is "キャッシュを消去して開始" then
try
do shell script "rm -dr /Applications/World\\ of\\ Warcraft/Cache/WDB/"
do shell script "open -a /Applications/World\\ of\\ Warcraft/World\\ of\\ Warcraft.app/"
on error
do shell script "open -a /Applications/World\\ of\\ Warcraft/World\\ of\\ Warcraft.app/"
end try

--「開始」ボタンを押すとキャッシュを消さずにゲームが始まります。
else if WOWCACHE is "開始" then
do shell script "open -a /Applications/World\\ of\\ Warcraft/World\\ of\\ Warcraft.app/"

--「今はしない」ボタンを押すとそのまま終了します。
else if WOWCACHE is "今はしない" then

end if
end tell