I love the Opera web browser, but it does have a couple of quirks.
One is searching from the address bar. I run Opera with as few panels showing as I can get away with so that I have more screen for the pages. So I use the address bar to search by typing the g, a space and the search string. That takes me to Google with the search already done.
But every now and then I forget to add the g and space. At this point, Opera takes my nicely formatted search string, removes all the spaces (so I can't just copy & paste :roll: ) and sends me to an error page.
It doesn't take very long for that to get old.
So a little script to fix that. Hope someone else finds it useful
#SingleInstance, Ignore Gosub, MenuTray SetTitleMatchMode, 3 SetTimer, FilterSpaces, 300 ;Use timers to make it easier to use multiple filters at one time SetTimer, FilterSpaces, Off SetTimer, FilterPeriods, 300 SetTimer, FilterPeriods, Off SetTimer, FilterIllegals, 300 SetTimer, FilterIllegals, Off SendMode, Play ;Set all Sends to act like SendPlay Hotkey, IfWinActive, ahk_class OpWindow ;Set hotkey to work only when Opera is active Hotkey, $Enter, WeFix Hotkey, IfWinActive, ahk_class OpWindow ;Set hotkey to work only when Opera is active (Yes, for every hotkey) Hotkey, $NumPadEnter, WeFix Fixed := 0 ;This will keep track of what threads have finished so the clean-up routine will know when it is safe to restore clipboard, etc... Return ;--- *** Main Program *** --- WeFix: WinGetActiveTitle, CurrentTitle if CurrentTitle = Compose message - Opera ;Filter out the Opera 'Compose E-mail' page { Send, {Enter} Gosub, MenuSuspend WinWaitNotActive, Compose message - Opera Gosub, MenuSuspend CurrentTitle := Return } if CurrentTitle = Blank page - Opera { ClipSaved := ClipboardAll ;Back-up the Clipboard Clipboard := ;and empty it Send, {LCtrl Down}a{LCtrl Up}{LCtrl Down}c{LCtrl Up}{Enter}{Tab} ;Copy to Clipboard what was entered into the address bar (if anything) } Else { ControlGetFocus, ControlCheck, A ;Need to filter so that the Enter key doesn't disrupt normal browser activities if ControlCheck = OperaWindowClass1 ;Most normal Opera controls are of this class... { Send, {Enter} Return } } if CurrentTitle != Blank page - Opera { ClipSaved := ClipboardAll ;Back-up the Clipboard Clipboard := ;and empty it Send, {Enter}{LCtrl Down}l{LCtrl Up}{LCtrl Down}c{LCtrl Up} ;Copy to Clipboard what was entered into the address bar (if anything) if Clipboard = { Fixed := 3 Gosub, CleanUp Return } Else { Send, {F9} } } Address = %Clipboard% ;Copy what was in address bar into a Var to work on StringLower, AddressCaseLower, Address ;Convert it to lower-case, just to be on the safe side StringMid, GotG, AddressCaseLower, 1, 2 ;Check if user included the g at the beginning... if GotG = g%A_Space% { Fixed := 3 Gosub, CleanUp ;the g was there, nothing we need to do Return } ifInString, Address, %A_Space% ;A URL shouldn't contain spaces... Opera will try to fix it { if FilterSpace = 1 ;User elected to not have Opera fix it... go directly to Google { Goto, FixIt Return } Else { SpacesTimer := A_TickCount SetTimer, FilterSpaces, On } } Else { Fixed++ } ifNotInString, Address, . ;URLs always contain at least 1 period... { PeriodsTimer := A_TickCount SetTimer, FilterPeriods, On } Else { Fixed++ } if FilterIllegal = 1 ;Characters like '!' and '\' aren't allowed in URLs { IllegalsTimer := A_TickCount SetTimer, FilterIllegals, On } Else { Fixed++ } Gosub, CleanUp Return ;--- If user elected to wait for error if URL contains spaces, timer will run this routine FilterSpaces: WinGetActiveTitle, NewTitle TimeRunning := A_TickCount-PeriodsTimer if TimeRunning > 5000 { SetTimer, FilterSpaces, Off Fixed++ ;We timed out Gosub, CleanUp Return } If NewTitle = Error - Opera { SetTimer, FilterIllegals, Off SetTimer, FilterSpaces, Off SetTimer, FilterPeriods, Off Goto, FixIt } NewTitle := Return ;--- This will run regardless, looking for URLs without periods... FilterPeriods: WinGetActiveTitle, NewTitle TimeRunning := A_TickCount-PeriodsTimer if TimeRunning > 5000 { SetTimer, FilterPeriods, Off Fixed++ ;We timed out Gosub, CleanUp Return } If NewTitle = Error - Opera { SetTimer, FilterIllegals, Off SetTimer, FilterSpaces, Off SetTimer, FilterPeriods, Off Goto, FixIt } NewTitle := Return ;--- If user elected to filter Illegal characters, timer will run this routine FilterIllegals: WinGetActiveTitle, NewTitle TimeRunning := A_TickCount-IllegalsTimer if TimeRunning > 5000 { SetTimer, FilterIllegals, Off Fixed++ ;We timed out Gosub, CleanUp Return } If NewTitle = Illegal URL - Opera { SetTimer, FilterIllegals, Off SetTimer, FilterSpaces, Off SetTimer, FilterPeriods, Off Goto, FixIt } NewTitle := Return ;----------------- FixIt: Thread, Priority, 1 ;Set the thread priority higher than the timed threads to prevent interruptions (just in case) Send, {LCtrl Down}l{LCtrl Up}{Backspace}g%A_Space% SendRaw, %Address% ;Use SendRaw so %Address% is sent exactly as it was typed Send, {Enter}{F9} Fixed := 3 Gosub, CleanUp Thread, Priority, 0 Return ;----------------- CleanUp: ;Resore the Clipboard and clean up if Fixed < 3 ;Wait for all timed routines to finish. If the URL needed fixed, this will be 3 regardless { Return } Thread, Priority, 1 ;Set the thread priority higher than the timed threads to prevent interruptions (just in case) Clipboard := ClipSaved ClipSaved := ControlCheck := AddressCaseLower := Address := ControlCheck := CurrentTitle := NewTitle := Fixed := 0 TimeRunning := IllegalsTimer := PeriodsTimer := SpacesTimer := Thread, Priority, 0 Return ;--- *** /Main Program *** --- ;--- Tray Menu setup MenuTray: IniRead, FilterSpace, OSF.ini, Filters, FilterSpace if FilterSpace = Error { NoIni := 1 FilterSpace := 0 ;If set to 1, all space will be automatically filtered (sent to Google) } IniRead, FilterIllegal, OSF.ini, Filters, FilterIllegal if FilterIllegal = Error { NoIni := 1 FilterIllegal := 1 ;If set to 0, the Illegal URL page will not trigger a Google search } Menu, Tray, NoStandard Menu, SpaceSubmenu, add, &All, MenuFilterSpace Menu, SpaceSubmenu, add, &Wait, MenuFilterSpace if FilterSpace = 1 { Menu, SpaceSubmenu, Check, &All } Else { Menu, SpaceSubmenu, Check, &Wait } Menu, tray, add, Filter &Spaces, :SpaceSubmenu Menu, IllegalSubmenu, add, &On, MenuFilterIllegal Menu, IllegalSubmenu, add, O&ff, MenuFilterIllegal if FilterIllegal = 1 { Menu, IllegalSubmenu, Check, &On } Else { Menu, IllegalSubmenu, Check, O&ff } Menu, tray, add, Filter &Illegal URLs, :IllegalSubmenu Menu, Tray, Add Menu, Tray, Add, S&uspend Hokeys, MenuSuspend Menu, Tray, Add, E&xit, MenuExit Return MenuFilterSpace: if A_ThisMenuItem = &Wait { Menu, SpaceSubmenu, UnCheck, &All Menu, SpaceSubmenu, Check, &Wait FilterSpace := 0 } Else { Menu, SpaceSubmenu, Check, &All Menu, SpaceSubmenu, UnCheck, &Wait FilterSpace := 1 } if NoIni != 1 { IniWrite, %FilterSpace%, OSF.ini, Filters, FilterSpace } Return MenuFilterIllegal: if A_ThisMenuItem = O&ff { Menu, IllegalSubmenu, Check, O&ff Menu, IllegalSubmenu, UnCheck, &On FilterIllegal := 0 } Else { Menu, IllegalSubmenu, UnCheck, O&ff Menu, IllegalSubmenu, Check, &On FilterIllegal := 1 } if NoIni != 1 { IniWrite, %FilterIllegal%, OSF.ini, Filters, FilterIllegal } Return MenuSuspend: if IsSuspended = 1 { IsSuspended := 0 Suspend, Off Menu, Tray, ToggleCheck, S&uspend Hokeys } Else { IsSuspended := 1 Suspend, On Menu, Tray, ToggleCheck, S&uspend Hokeys } Return MenuExit: ExitApp
Since most of the major problems seem to be worked out, I've re-written the script.
In this version, you can change how it handles spaces and illegal characters through the Tray menu. It keeps track of the changes via an .ini file, but will run fine without it (just will not save your settings). The compiled version below will not work without the .ini file and will create one.
It has been changed to use timers to filter for error pages so that it can check for different errors at (nearly) the same time. This will also make it easier to modifiy if needed.
The settings are simple: By default, if you enter any spaces in the URL as you are typing it into the address bar and press the Enter key, Opera will attempt to correct them and find the page. If you set the Filter Spaces option to All in this script, any URLs you enter that contain spaces will be sent to a Google search automatically. If set to Wait, the script will wait up to 5 seconds for Opera to display an error page... if that happens within 5 seconds, the search goes to Google, and if not the script times out and lets Opera handle it.
The Filter Illegal URLs option has two settings: On and Off. Pretty easy to figure out that one
For those that like compiled scripts, you can get the compiled version here (there is no password and the script can be decompiled using Exe2Ahk). If you just want the default .ini file for it, grab that here (place it in the same folder as the script).
I Love Bugs! Please post them
Have fun!