AutoHotKey_Lで、Operaの前回セッションを確認・退避できるようにしてみた。
ふとAHK_Lに乗り換えたら、文字コード関連で動かなくなった「AutoHotKeyで、Operaの起動をより便利にしてみた。」のAHK_L版。
機能的には変わってない。
#WinActivateForce
SessionsPath := "セッション保存先のパス"
IniRead, WinCnt, %SessionsPath%autosave.win, session, window count
if("ERROR" != WinCnt)
{
FileRead, SessionBuf, %SessionsPath%autosave.win
FileDelete, %SessionsPath%autosaveA.win
FileAppend, %SessionBuf%, %SessionsPath%autosaveA.win, CP932
GoSub, SessionAnalyze
}
run, Opera.exeのパス, , , OpPid
OpTitle := "パスワード"
WinWaitActive, %OpTitle% ahk_pid %OpPid%, , 30
if(ErrorLevel != 0)
Exit
WinWaitNotActive, %OpTitle% ahk_pid %OpPid%, , 30
WinActivate, %OpTitle% ahk_pid %OpPid%, , 30
Exit
SessionAnalyze:
loop, %WinCnt%
{
IniRead, HisCnt, %SessionsPath%autosaveA.win, %A_index%history title, count
if("ERROR" == HisCnt)
Continue
HisCnt--
IniRead, WinTitle, %SessionsPath%autosaveA.win, %A_index%history title, %HisCnt%
WinTitles := WinTitles " " WinTitle "`n"
}
if("" == WinTitles)
return
MsgBox, 3, 表示後30秒で強制的に起動します。, 最終セッションを退避せずに起動しますか?`n`n◆最終セッションの内容◆`n%WinTitles%, 30
ifMsgBox, No
{
TimeNum := A_Now
FileMove, %SessionsPath%autosave.win, %SessionsPath%%TimeNum%.win
if(0 < ErrorLevel)
loop
{
FileMove, %SessionsPath%autosave.win, %SessionsPath%%TimeNum%_%A_Index%.win
if(0 == ErrorLevel)
Break
}
}
ifMsgBox, Cancel
Exit
return
IniReadはSJISしか読み込めないようなので、自動保存セッションをSJISに変換するという力技。文字化けするかもしれんが気にすんな!