Jump to content


Photo

Google Site Search [ I'm Feeling Lucky ] - 46L


  • Please log in to reply
16 replies to this topic

#1 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 13 August 2012 - 08:48 PM

Simple & minimal Google Site Search Script

Posted Image

Posted Image

[*:2hzcv74e]Use Hotkey Ctrl+Alt+g to Hide/Show GUI. To exit, use TrayIcon
[*:2hzcv74e]I'm Feeling Lucky is default. To view Google site search results - Keep LCtrl down while clicking a button.
[*:2hzcv74e]The first button is the default button.
[*:2hzcv74e]Empty buttons ( to maintain symmetry ) will be tolerated. Use || to create empty buttons
[*:2hzcv74e]To adjust Bitmap size, pass W & H to Params 4 & 5 in LoadImage() call.
[color=#225599]/*                                                         _____  _______  ______  _
  gifl.ahk, Google [ I'm Feeling Lucky ] Site Search      (_____)(_______)(______)(_) 46L
                                                         (_)  ___   (_)   (_)__   (_)
  Created: 14-Aug-2012 /  Last Modified: 14-Aug-2012     (_) (___)  (_)   (____)  (_)
  SKAN ( A.N.Suresh Kumar,  arian.suresh@gmail.com )     (_)___(_)__(_)__ (_)     (_)____
  www.autohotkey.com/community/viewtopic.php?t=90096      (_____)(_______)(_)     (______)
                                                      */[/color]

#SingleInstance, Force
SetWorkingDir %A_ScriptDir%

IfNotExist, gifl.ico, URLDownloadToFile, http://www.google.com/favicon.ico, gifl.ico
Menu, Tray, UseErrorLevel
Menu, Tray, Icon, gifl.ico, 1

ButtonW := [color=#FF0000]96[/color],  ButtonH := [color=#FF0000]32[/color],  ButtonSpacing := [color=#FF0000]3[/color],   BPR := ButtonsPerRow := [color=#FF0000]5[/color]

Sites= [color=#008000]; ButtonText/BMP  | SearchSiteURL                                 | ExtraSearchInfo[/color]
(      [color=#008000]; ----------------+-----------------------------------------------+----------------[/color]
         &IMDb           | imdb.com/title                                |
         &OpenSubtitles  | opensubtitles.org/en/search/sublanguageid-eng |
         The&TVDb        | thetvdb.com/?tab=series&id                    | +series+info
         Addic&7ed       | addic7ed.com/show                             |
         TV&Subtitles    | www.tvsubtitles.net/tvshow                    |
         &AutoHotkey     | autohotkey.com                                |
         &MSDN           | msdn.microsoft.com/en-us/library              |
         &Wikipedia      | en.wikipedia.org/wiki                         |
         &Dictionary     | dictionary.reference.com/browse               |
         &UrbanDict      | urbandictionary.com/define.php?term=          |
)     [color=#008000];  ----------------^-----------------------------------------------^----------------[/color]
StringSplit, BTN, Sites, `n, %A_Space%

Gui +AlwaysOnTop +LastFound
hGui := WinExist()
Gui, Font, S10, Arial
Gui, Add, Edit, % "hwndhEdit vSearch xm w" ( ButtonW * BPR ) + ( (BPR-1) * ButtonSpacing )
Loop % ( BTN0 ) {
  Coord := Mod( A_Index,BPR ) = 1 ? "xm y+" ButtonSpacing : "yp x+" ButtonSpacing
  StringSplit, Par, BTN%A_Index%, |, %A_Space%
  Gui, Add, Button, %Coord% w%ButtonW% h%ButtonH% vBTN%A_Index% hwndID gGoogleIFL,  %Par1%
  If FileExist( BMP := RegExReplace( Par1, "&" ) ".bmp" ) {
    Control, Style, +0x80, , ahk_id %ID%
    hBM := DllCall( "LoadImage", UInt,0, Str,BMP, Int,0, Int,0, Int,0, UInt,0x2010, UInt )
    SendMessage, 0xF7, 0x0, %hBM% ,, ahk_id %ID% [color=#008000]; BM_SETIMAGE > IMAGE_BITMAP[/color]
  } GuiControl, +Default, Button1 [color=#008000]; Flag the first Button as default[/color]
} Gui, Show, AutoSize, Google Site Search [ I'm Feeling Lucky ]

[color=#FF0000]^!g::[/color]GoSub, GuiEscape                                  [color=#008000]; // end of auto-execute section //[/color]

[color=#FF2000]GoogleIFL:[/color]
  StringSplit, Par, %A_GuiControl%, |, %A_Space%
  GuiControlGet, Search
  If ! ( Search="" || Par1="" )
     Run, % """http://www.google.com/search?" ( ! GetKeyState( "LControl" ) ? "sourceid="
     . "navclient&btnI&" : "" ) "q=" Search ( Par3<>"" ? Par3 : "" ) "+site:" Par2 . """"
[color=#FF2000]GuiEscape:[/color]
  GuiControl, Focus, Search
  SendMessage, 0xB1, 0, -1, Edit1, ahk_id %hGUI% [color=#008000]; EM_SETSEL > Select All[/color]
  Gui, Show, % ( DllCall( "IsWindowVisible", UInt,hGui ) ? "Hide" : "" )

Optional:

:arrow: If a Bitmap matching the 'ButtonText' is found in the 'Script Folder', it will be automatically applied to the button.

The following 10 bitmaps ( alphabetical order ) are sized 92x32 ( 8bit, 4022 bytes each )

http://dl.dropbox.com/u/6428211/AutoHotkey/GIFL/Addic7ed.bmp http://dl.dropbox.co.../AutoHotkey.bmp http://dl.dropbox.co.../Dictionary.bmp http://dl.dropbox.co...y/GIFL/IMDb.bmp http://dl.dropbox.co...y/GIFL/MSDN.bmp
http://dl.dropbox.com/u/6428211/AutoHotkey/GIFL/OpenSubtitles.bmp http://dl.dropbox.co...TVSubtitles.bmp http://dl.dropbox.co...IFL/TheTVDb.bmp http://dl.dropbox.com/u/6428211/AutoHotkey/GIFL/UrbanDict.bmp http://dl.dropbox.com/u/6428211/AutoHotkey/GIFL/Wikipedia.bmp

Note: The accelerator keys will still work!
You may use this <snippet> to download the 10 bitmaps


#2 DataLife

DataLife
  • Members
  • 729 posts

Posted 14 August 2012 - 12:02 AM

I just tried it and it is very nice.

thanks
DataLife

#3 DataLife

DataLife
  • Members
  • 729 posts

Posted 14 August 2012 - 12:23 AM

I added &Google as the button name and google.com as the SearchSiteURL. I put an 92x32 google.bmp in the script folder.

It added a button and it works great but with no picture on the button.

What did I do wrong?

DataLife

#4 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 14 August 2012 - 07:39 AM

It added a button and it works great but with no picture on the button.What did I do wrong?


Insert a MsgBox % hBM after DllCall( "LoadImage" ... ). If you see a 0 then either file is not in the script folder or the file is in incorrect format. for example, you could have saved a PNG file with BMP extension.

I added &Google as the button name and google.com as the SearchSiteURL.

Why would you want to do a 'site search' on Google itself? :roll:

If you want a generic 'goto first result', then I suggest you to avoid SearchSiteURL

Sites= [color=#008000]; ButtonText/BMP  | SearchSiteURL                                 | ExtraSearchInfo[/color]
(      [color=#008000]; ----------------+-----------------------------------------------+----------------[/color]
         &Google         |                                               |
         &IMDb           | imdb.com/title                                |
         &OpenSubtitles  | opensubtitles.org/en/search/sublanguageid-eng |
         The&TVDb        | thetvdb.com/?tab=series&id                    | +series+info
         Addic&7ed       | addic7ed.com/show                             |
         TV&Subtitles    | http://www.tvsubtitles.net/tvshow             |
         &AutoHotkey     | autohotkey.com                                |
         &MSDN           | msdn.microsoft.com/en-us/library              |
         &Wikipedia      | en.wikipedia.org/wiki                         |
         &Dictionary     | dictionary.reference.com/browse               |
         &UrbanDict      | urbandictionary.com/define.php?term=          |
)     [color=#008000];  ----------------^-----------------------------------------------^----------------[/color]

... and alter If ! ( Search="" || Par2="" )
to If ! ( Search="" || Par2="" )

Edit: Applied ^above change in Title post.

Here is a bitmap for google: http://dl.dropbox.co...GIFL/Google.bmp

#5 DataLife

DataLife
  • Members
  • 729 posts

Posted 14 August 2012 - 07:55 AM

Why would you want to do a 'site search' on Google itself?


I just wanted to be able to search with Google using your script. (Not site search)

My Google button image is now working and I did not make any changes to the bmp or code.

I have no clue why it was not working before.

thanks
DataLife

#6 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 15 August 2012 - 02:24 PM

I just wanted to be able to search with Google using your script


Have applied it in following:


Variant: GILFW.ahk
[*:tp82jcyo]If SearchSiteURL begins with 'http', then sitesearch is not performed and the url is suffixed with search term and run.
[*:tp82jcyo]Default button is google. Enter takes you to 'Search results page' and Ctrl+Enter will redirect to the first result.
[*:tp82jcyo]This version uses BCM_SETIMAGELIST, but again, button bitmaps are optional.

Posted Image
The BITMAPS: GIFLW.zip 27.4 KiB

The SCRIPT:

/*
                                                           _____  _______  ______  _
  giflw.ahk: Google IFL Site Search Wizard                (_____)(_______)(______)(_) 2.0
                                                         (_)  ___   (_)   (_)__   (_)
  Created: 14-Aug-2012 /  Last Modified: 15-Aug-2012     (_) (___)  (_)   (____)  (_) W..
  SKAN ( A.N.Suresh Kumar,  arian.suresh@gmail.com )     (_)___(_)__(_)__ (_)     (_)____
  www.autohotkey.com/community/viewtopic.php?t=90096      (_____)(_______)(_)     (______)

*/

Button_SetBitmap( hWnd, fBMP, mL=2, mT=2, mR=4, mB=2 ) { ; By SKAN    Created: 15-Aug-2012
; www.autohotkey.com/community/viewtopic.php?p=559230#p559230
 hBM := DllCall( "LoadImage", UInt,0, Str,fBMP, UInt,0, Int,0, Int,0, UInt,0x2010, UInt )
 VarsetCapacity( BM, 24, 0 ),   DllCall( "GetObject", UInt,hBM, UInt,24, UInt,&BM )
 W := NumGet( BM,4 ), H := NumGet( BM,8 ), BPP := NumGet( BM,18,"UShort" )
 hIL := DllCall( "ImageList_Create", Int,W, Int,H, UInt,BPP, Int,1, Int,1, UInt )
 DllCall( "ImageList_Add", UInt,hIL, UInt,hBM, Int,0 ),  DllCall("DeleteObject", UInt,hBM)
 VarSetCapacity( BIL, 24, 0 ), NumPut(  hIL, BIL ), NumPut( mL, BIL, 4 )
         NumPut( mT, BIL, 8 ), NumPut( mR, BIL,12 ), NumPut( mB, BIL,16 )
Return hIL, ErrorLevel:= !DllCall("SendMessage", UInt,hWnd, UInt,0x1602, Int,0, UInt,&BIL)
}

#SingleInstance, Force
SetWorkingDir %A_ScriptDir%

IfNotExist, gifl.ico, URLDownloadToFile, http://www.google.com/favicon.ico, gifl.ico
Menu, Tray, UseErrorLevel
Menu, Tray, Icon, gifl.ico, 1

ButtonW := 110,  ButtonH := 32,  ButtonSpacing := 5,   BPR := ButtonsPerRow := 4

Sites=
(
Google         | http://www.google.com/search?q=                | &sourceid=navclient&btnI
Map&s          | http://maps.google.com/maps?q=                 |
Imag&es        | http://google.com/search?site=imghp&tbm=isch&q=| &tbs=itp:face
&IMDb          | imdb.com/title                                 |
&AutoHotkey    | autohotkey.com                                 |
&MSDN          | msdn.microsoft.com/en-us/library               |
The&TVDb       | thetvdb.com/?tab=series&id                     | +series+info
&OpenSubs      | opensubtitles.org/en/search/sublanguageid-eng  |
&Wikipedia     | en.wikipedia.org/wiki                          |
Wikima&pia     | wikimapia.org                                  | +place+comments
Addic&7ed      | addic7ed.com/show                              |
T&V-Subtitles  | tvsubtitles.net/tvshow                         |
&Dictionary    | http://dictionary.reference.com/browse/        |
T&hesaurus     | http://thesaurus.com/browse/                   |
&UrbanDict     | http://www.urbandictionary.com/define.php?term=|
&YouTube       | youtube.com/watch?v=                           | +hd+video
)
StringSplit, BTN, Sites, `n, %A_Space%

Gui +AlwaysOnTop +LastFound
hGui := WinExist()
Gui, Font, S10, Arial
Gui, Add, Edit, % "vSearch xm w" ( ButtonW * BPR ) + ( (BPR-1) * ButtonSpacing )
Loop % ( BTN0 ) {
  XY := Mod( A_Index,BPR ) = 1 ? "xm y+" ButtonSpacing : "yp x+" ButtonSpacing
  StringSplit, Par, BTN%A_Index%, |, %A_Space%
  Gui, Add, Button, %XY% w%ButtonW% h%ButtonH% vBTN%A_Index% hwndhwnd gGoogleIFLW, %Par1%
  If FileExist( BitmapFile := RegExReplace( Par1, "&" ) ".bmp" ) {
     GuiControl, +Left, BTN%A_Index% ; Left-aligns the Button text / BS_LEFT = 0x100
     Button_SetBitmap( hwnd, BitmapFile )
  }
}
GuiControl, +Default, Button1 ; Flag the first Button as default
Gui, Show, AutoSize, Google [ I'm Feeling Lucky ] Site Search Wizard

^!g::GoSub, GuiEscape                                  ; // end of auto-execute section //

GoogleIFLW:
  StringSplit, Par, %A_GuiControl%, |, %A_Space%
  GuiControlGet, Search
  If ! ( Search="" || Par1="" )
  If ( SubStr( Par2,1,4 ) <> "http" )
       Run, % """http://www.google.com/search?" ( !GetKeyState( "LControl" ) ? "sourceid="
      . "navclient&btnI&" : "" ) "q=" Search ( Par3<>"" ? Par3 : "" ) "+site:" Par2 . """"
  Else Run, % """" Par2 Search ( !GetKeyState( "LControl" ) ? "" : Par3 ) """"
GuiEscape:
  GuiControl, Focus, Search
  SendMessage, 0xB1, 0, -1, Edit1, ahk_id %hGUI% ; EM_SETSEL > Select All
  Gui, Show, % ( DllCall( "IsWindowVisible", UInt,hGui ) ? "Hide" : "" )


#7 DataLife

DataLife
  • Members
  • 729 posts

Posted 15 August 2012 - 03:00 PM

I just tried it. Looks and works great.

thanks
DataLife

#8 klownboy

klownboy
  • Members
  • 76 posts

Posted 15 August 2012 - 03:45 PM

Hey SKAN,
Very nice, and more importantly, useful script! I was hoping though to move any bitmaps, at least the ones for the GUI into a subdirectory so they're not in my scripts directory (e.g., %A_ScriptDir%\GoogleSearch). My script folder is getting out of hand. Would there be any easy way of modifying the script(s) to accomplish that either with your original or variant script?
Thanks,
Ken

#9 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 15 August 2012 - 07:53 PM

Looks and works great.


I am glad you like it. :)

move any bitmaps, at least the ones for the GUI into a subdirectory so they're not in my scripts directory (e.g., %A_ScriptDir%\GoogleSearch).


Move the bitmaps ( as well as gifl.ico ).. and then alter the line: SetWorkingDir %A_ScriptDir%
to: SetWorkingDir %A_ScriptDir%\GoogleSearch

:)

#10 klownboy

klownboy
  • Members
  • 76 posts

Posted 15 August 2012 - 08:03 PM

Thanks SKAN, I was looking through the meat of your code looking for directory information and totally missed the 2nd line. Even a nub like me could have changed that without asking for help if I had seen it...oops! :oops:
Thanks again,
Ken

#11 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 15 August 2012 - 09:17 PM

All button images used in GIFLW.ahk were originally in PNG format.
I used PixelFormer to convert them into 'Alpha Bitmaps' to preserve the background transparency.

Converting 32 bpp Icons or Alpha Transparent PNG into Alpha Bitmaps requires 2 steps in PixelFormer:

1) File > Import > Select your Icon / PNG
2) File > Export > Bitmap

You will be prompted with following dialog and you should select 32 bpp:

Posted Image


More info: <!-- m -->http://www.qualibyte.com/pixelformer/<!-- m -->

Posted Image


ahk.bmp 32 bpp / Alpha Bitmap ( 73.1 KiB )

https://dl.dropbox.com/u/6428211/Sample/ahk.bmp

In above BITMAP, the background is transparent in Google Chrome.. However, I do not know about other browsers!

#12 klownboy

klownboy
  • Members
  • 76 posts

Posted 16 August 2012 - 03:31 PM

Hi SKAN,
I'm having trouble with no bitmaps showing on your "variant" code. I placed the extracted bitmaps from GIFLW.ZIP directly in the scripts folder. The program works (i.e., the non-bitmap text version works fine). This is the case on both my laptop and desktop both running Windows 7 Home Premium, 64 bit. For your info, I'm using AHK_L x64 Unicode, latest version 1.1.08.00. The first or original version works just great and the bitmaps load and show up fine. That version also worked when I placed the bitmaps in a sub-directory (%A_ScriptDir%\GoogleSearch) as we had discussed earlier...thanks again. I even managed to change one of the programs to XYplorer forum with a new bitmap. The new variant version (GILFW.ahk) however did not load the bitmaps contained within GIFLW.ZIP whether I had them in a subdirectory or placed them directly in the scripts folder (I did change the SetWorkingDir as required for each case). I tried it numerous times with no luck (exiting, reloading, restarting etc.) Not sure what's going on.
Thanks,
Ken

#13 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 16 August 2012 - 04:21 PM

For your info, I'm using AHK_L x64 Unicode, latest version 1.1.08.00.


Uh Oh! Button_SetBitmap() is totally incompatible with AHK_L 64 Bit :(
I do not have the means to test x64..
I suggest you post the following snippet in Support forum requesting x64 compatibility.

SetWorkingDir, %A_ScriptDir%

IfNotExist, Google.bmp
  URLDownloadToFile, http://dl.dropbox.com/u/6428211/Sample/Google.bmp, Google.bmp

Gui, Add, Button, w96 h32 +Left hwndhWnd, &Google
Button_SetBitmap( hWnd, "Google.bmp" )
Gui, Show


Button_SetBitmap( hWnd, fBMP, mL=2, mT=2, mR=4, mB=2 ) { ; By SKAN    Created: 15-Aug-2012
; www.autohotkey.com/community/viewtopic.php?p=559230#p559230
 hBM := DllCall( "LoadImage", UInt,0, Str,fBMP, UInt,0, Int,0, Int,0, UInt,0x2010, UInt )
 VarsetCapacity( BM, 24, 0 ),   DllCall( "GetObject", UInt,hBM, UInt,24, UInt,&BM )
 W := NumGet( BM,4 ), H := NumGet( BM,8 ), BPP := NumGet( BM,18,"UShort" )
 hIL := DllCall( "ImageList_Create", Int,W, Int,H, UInt,BPP, Int,1, Int,1, UInt )
 DllCall( "ImageList_Add", UInt,hIL, UInt,hBM, Int,0 ),  DllCall("DeleteObject", UInt,hBM)
 VarSetCapacity( BIL, 24, 0 ), NumPut(  hIL, BIL ), NumPut( mL, BIL, 4 )
         NumPut( mT, BIL, 8 ), NumPut( mR, BIL,12 ), NumPut( mB, BIL,16 )
Return hIL, ErrorLevel:= !DllCall("SendMessage", UInt,hWnd, UInt,0x1602, Int,0, UInt,&BIL)
}

Also, the DllCall for IsWindowVisible() ( last line of the Script ) would need a fix.

#14 klownboy

klownboy
  • Members
  • 76 posts

Posted 17 August 2012 - 12:49 PM

Thanks SKAN, I'm actually quite content using your original version which has no issues with the x64 version, but when I get a chance I'll ask the question in Support concerning a mod to your code to make it work on x64.

By the way, is there a way (probably a simple way) to change the script such that the script loads but does not open (i.e., it does auto execute the hotkey). I want the same Hotkey ^!g but I want to just load the script along with others on computer startup , but I don't want the script to bring up the GoogleSearch interface until I actually need it by hitting the hotkey.
Thanks again,
Ken

#15 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 17 August 2012 - 01:20 PM

just load the script along with others on computer startup , but I don't want the script to bring up the GoogleSearch interface until I actually need it


Just put a Hide in 'Gui Options', like:
} Gui, Show, AutoSize Hide, Google Site Search [ I'm Feeling Lucky ]