AutoHotkey_Lで、Opera12の起動を便利にしてみた。
前ver.のOpera12対応版。前ver.からフォークしたRamDisk運用補助の小規模改善も反映済み。
Opera12対応は「マスターパスワードダイアログのタイトル変更に追従」「マスターパスワードダイアログを最前面表示するように」。Operaのver.によって最前面でなくなるのはなんなの、うっかりなの?
ちなみに小規模改善の内容は「FastForward.ini初期化の対策」「autosave.winの2世代バックアップ」「セッション退避ダイアログのカウントダウン」。
FastForward.ini初期化対策は、同じ場所にFastForward_backup.iniがあれば上書きするよってだけの機能。
; --------- --------- --------- --------- ---------
; RunOpera.ahk ver.2.1.0
; --------- --------- --------- --------- ---------
#WinActivateForce
OperaPath := "" ; Opera.exeのフルパス。末尾は"\"。
SessionsPath := OperaPath "profile\sessions\" ; セッションフォルダのフルパスを指定。末尾は"\"。
BookmarksPath := OperaPath "profile\bookmarks.adr" ; bookmarks.adrのフルパスを指定。
TimeLimit := 30 ; 最終セッション退避確認ダイアログを自動でスキップするまでの秒数。
AutoConvSW := 1 ; 最終セッションを退避させる場合、自動でブックマークに変換する設定。 0:変換しない。 1:変換する。
ACMoveSW := 1 ; 自動変換(↑)したセッションを隔離する設定。 0:隔離しない。 1:隔離する。
HisReadSW := 0 ; タブ履歴(タブで表示したページの履歴)の設定。 0:最新のみ読み込む。 1:すべて読み込む。
WriteTrgSW := 1 ; ブックマーク情報を書き込む場所の設定。 0:セッションフォルダにテキストで保存。 1:bookmarks.adrに書き込む。
; --------- --------- --------- --------- ---------
IfNotExist, %SessionsPath%
{
MsgBox, 16, , セッションフォルダが見つかりません。`n%SessionsPath%
Exit
}
If (1 == WriteTrgSW) {
IfNotExist, %BookmarksPath%
{
MsgBox, 16, , bookmarks.adrが見つかりません。`n%BookmarksPath%
Exit
}
}
IfExist, %SessionsPath%autosave.win
GoSub, SessionAnalyze
FileCopy, %OperaPath%ui\fastforward_backup.ini, %OperaPath%ui\fastforward.ini, 1 ; FastForward.ini初期化の対策。
FileCopy, %SessionsPath%autosave_RunOpBak.win, %SessionsPath%autosave_RunOpBak2.win, 1 ; ↓セッション退避etc.を実行しない時も念のため2世代バックアップ。
FileCopy, %SessionsPath%autosave.win, %SessionsPath%autosave_RunOpBak.win, 1
Run, %OperaPath%opera.exe, , , OpPid
WinWait, ahk_pid %OpPid%, , 60
if !ErrorLevel {
ifWinExist, Opera へようこそ ahk_pid %OpPid%
{
WinActivate
WinWaitClose
}
} else {
return
}
WinWait, マスターパスワードを入力してください ahk_pid %OpPid%, , 5
If ErrorLevel
return
WinSet, Topmost, ON
WinActivate
Sleep, 300
ExitApp
; --------- --------- --------- --------- ---------
SessionAnalyze:
FileRead, OSession, *P65001 *t %SessionsPath%autosave.win
If (0 != ErrorLevel) {
MsgBox, 48, , Sessionの読み込みに失敗しました。`n%SessionsPath%autosave.win
return
}
Idx := 0
WinTitles := ""
Loop {
Idx := RegExMatch(OSession, "\[(\d+)history url\].+?count=(.*?)\n", $, Idx + 1)
If (0 == Idx)
Break
WinNum := $1
HisNum := $2 - 1
HisTitle := GetHisTitle(OSession, WinNum, HisNum, Idx)
WinTitles := WinTitles " " HisTitle "`n"
}
If("" == WinTitles)
return
SetTimer, RenewCount, 1000
MsgBox, 259, 退避確認(30秒後に通常起動), 起動時に最終セッションを退避しますか?`n`n◆最終セッションの内容◆`n%WinTitles%, %TimeLimit%
SetTimer, RenewCount, Off
IfMsgBox, Yes
{
TimeNum := A_Now
BackupName := TimeNum ".win"
Loop {
FileMove, %SessionsPath%autosave.win, %SessionsPath%%BackupName%
If(0 == ErrorLevel)
Break
BackupName := TimeNum "_" A_Index ".win"
}
If (1 == AutoConvSW)
GoSub, SessionConvert
}
IfMsgBox, Cancel
Exit
return
; --------- --------- --------- --------- ---------
RenewCount:
IfWinExist, 退避確認( ahk_class #32770
{
TimeLimit--
WinSetTitle, 退避確認(%TimeLimit%秒後に通常起動)
if !TimeLimit
SetTimer, RenewCount, Off
}
return
; --------- --------- --------- --------- ---------
SessionConvert:
If (1 == WriteTrgSW)
FileCopy, %BookmarksPath%, %BookmarksPath%_%A_Now%
CmdLine := SessionsPath BackupName
SplitPath, CmdLine, , , , SessionName
Result := "#FOLDER`n NAME=[Session] " SessionName "`n`n"
ResultBuf := Result
Idx := 0
Loop {
Idx := RegExMatch(OSession, "\[(\d+)history url\].+?count=(.*?)\n", $, Idx + 1)
If (0 == Idx)
Break
WinNum := $1
HisNum := $2 - 1
HisTitle := GetHisTitle(OSession, WinNum, HisNum, Idx)
HisUrl := GetHisUrl(OSession, WinNum, HisNum, Idx)
If (0 == HisReadSW) { ; タブ履歴を無視する場合
Result .= "#URL`n NAME=" HisTitle "`n URL=" HisUrl "`n`n"
Continue
}
StringLen, HisNumLen, HisNum
If (0 == HisNum) {
Result .= "#URL`n NAME=[" ZeroSupply(HisNum, HisNumLen) "] " HisTitle "`n URL=" HisUrl "`n`n"
Continue
}
Result .= "#FOLDER`n NAME=" HisTitle "`n`n#URL`n NAME=[" ZeroSupply(HisNum, HisNumLen) "] " HisTitle "`n URL=" HisUrl "`n`n"
Loop, %HisNum% {
HisNum--
HisTitle := GetHisTitle(OSession, WinNum, HisNum, Idx)
HisUrl := GetHisUrl(OSession, WinNum, HisNum, Idx)
Result .= "#URL`n NAME=[" ZeroSupply(HisNum, HisNumLen) "] " HisTitle "`n URL=" HisUrl "`n`n"
}
Result .= "-`n`n"
}
If (ResultBuf == Result)
return
Result .= "-`n`n"
If (1 == WriteTrgSW) {
FileAppend, %Result%, %BookmarksPath%, CP65001
} Else {
FileDelete, %CmdLine%.txt
FileAppend, %Result%, %CmdLine%.txt, CP65001
}
If (1 == ACMoveSW) {
IfNotExist, %SessionsPath%AutoConv\
FileCreateDir, %SessionsPath%AutoConv\
FileMove, %CmdLine%, %SessionsPath%AutoConv\%BackupName%
If (0 != ErrorLevel)
MsgBox, 48, , 変換済みセッションの移動に失敗しました。`n%SessionsPath%AutoConv\
}
return
; --------- --------- --------- --------- ---------
GetHisTitle(OSession, WinNum, HisNum, Idx){
RegExMatch(OSession, "\[" WinNum "history title\].+?" HisNum "=(.*?)\n", $)
return $1
}
GetHisUrl(OSession, WinNum, HisNum, Idx){
RegExMatch(OSession, "\[" WinNum "history url\].+?" HisNum "=(.*?)\n", $)
return $1
}
ZeroSupply(Num, Digit){
StringLen, NumLen, Num
LoopNum := Digit - NumLen
Loop, %LoopNum%
Num := "0" Num
return, Num
}
Opera12、タブ大量でも起動が軽くなったのがいいね。でもUJS Managerが使えなくなったのが痛い。というか標準で実装しろと。エクステンション作れ/使えってか。ごもっとも。
AutoHotkey_Lで、Opera12の起動を便利にしてみた。をちょっと改善。状況によってセッション退避やブックマーク変換が機能しない問題とか直ったはず(ちょっとしたってレベルじゃねーぞ。 作者にもわからんくなってきたので、機能をまとめてみる。 Operaの起動前に、前回終了時のセッション(AutoSave.win)の内容を確認できる。AutoSave.winを復元せずに、空のOperaを起動することができる。復元しない場合、AutoSave.winをブックマークに変換できる。AutoSave...... more
このAutoHotkeyって特定キー連射ってできるのでしょうか?もしできるとしたら1秒で最高何回できますか?