2011/09/01

MacBookAirその後

7月の時は、11インチ(Late2010)だったのに、今は、なぜか13インチ(Mid2011)を使っています。

ここ一ヶ月程で、環境が大きく変わりました。

NASストレージ(AirMacExtreme+WDの1TBを2台)も、追加。
これで自前Cloudが出来るようになりました。
ついでにAppleScriptで、NASマウントの自動化と、家と外での切り替えもさせてみたり(稚拙な出来ですけど……無駄に長いし……)
(Sleep復帰周りは、kernel.logで一応Wakeを吐き出していたので、使ってみました。正解なのかはわからず……)
(AppleEventのタイムアウトが出るし、ディープスリープからの復帰は、まだなんか不安定です)

マウントVolumeは、先に手動でマウントして、そのボリュームの「情報を見る」か⌘iで表示されるafp://名をコピペして入れます。
どこでもMyMacを使って外からマウントする場合も、同様に「情報を見る」からコピペします。

これを、AppleScriptエディタから「アプリケーション」形式で、「実行後、自動終了しない」として、好きな名前で保存。
出来たScriptを、ログイン時の起動項目に入れれば、どこでMBA開いても、自宅NASのボリュームがマウントされる環境になる、はず…


property addr1 : ""
property addr2 : ""
property IP_addr1 : "192.168.11." --外
property IP_addr2 : "192.168.1."  --家
property change_flg : 0
property sleep_flg1 : ""

on run
	delay 2
	set addr2 to IPv4 address of (get system info)
	set sleep_flg1 to do shell script "grep 'Wake reason' /var/log/kernel.log"
end run

on idle
	set sleep_flg2 to do shell script "grep 'Wake reason' /var/log/kernel.log"
	set addr2 to IPv4 address of (get system info)
	
	if sleep_flg1 is not sleep_flg2 then
		set sleep_flg1 to sleep_flg2
		--		display dialog "Sleep復帰。"
		if (offset in addr2 of "192.168.") > 0 then
			tell application "Finder"
				if not (exists disk "外付けHDD名") then
					set addr1 to ""
				end if
			end tell
			
			if addr1 is not "" then
				if addr1 is not addr2 then
					tell application "Finder"
						if (exists disk "外付けHDD名") then
							try
								eject "外付けHDD名"
							on error
								display dialog "外付けHDD名アンマウントできねー"
							end try
						end if
					end tell
					delay 1
				end if
			end if
		end if
	end if
	
	if (offset in addr2 of "192.168.") > 0 then
		tell application "Finder"
			if not (exists disk "外付けHDD名") then
				set change_flg to 2
			end if
		end tell
		
		if addr1 is not addr2 then
			set addr1 to addr2
			if (offset in addr1 of IP_addr1) = 0 then
				set place_flg to 0
			else
				set place_flg to 1
			end if
			
			set change_flg to 1
		end if
		
		if change_flg = 2 then
			set addr1 to addr2
			if (offset in addr1 of IP_addr1) = 0 then
				set place_flg to 0
			else
				set place_flg to 1
			end if
			
			set change_flg to 1
		end if
		
		if change_flg = 1 then
			tell application "Finder"
				if (exists disk "外付けHDD名") then
					try
						eject "外付けHDD名"
					on error
						display dialog "外付けHDD名アンマウントできねー"
					end try
				end if
			end tell
			
			set change_flg to 0
			
			if place_flg = 0 then
				tell application "Finder"
					if not (exists disk "外付けHDD名") then
						try
							mount volume "afp://AirMac接続時のafp+外付けHDD名"
						on error
							display dialog "マウントできねー"
						end try
					end if
				end tell
			else
				--			display dialog "WAN時マウント処理"
				tell application "Finder"
					if not (exists disk "外付けHDD名") then
						try
							mount volume "afp://AirMac接続時のafp+どこでもMyMacアカウント名+外付けHDD名"
						on error
							display dialog "マウントできねー"
						end try
					end if
				end tell
			end if
		end if
	else
		return 2
	end if
end idle

0 件のコメント:

コメントを投稿