How can I search selected word from existing Dictionary.com tab?

Get help with using AutoHotkey and its commands and hotkeys
my-lord
Posts: 45
Joined: 01 Apr 2018, 15:12

How can I search selected word from existing Dictionary.com tab?

16 Apr 2018, 11:36

Hello guys.I want to search selected word Dictionary.com.I type following script.

Code: Select all

^+g:: 
Send, ^c
sleep 50
parameter = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe http://www.dictionary.com/browse/"%clipboard%"
Run %parameter%
Return
But I don't want to create a new tab.I want to search from existing Dictionary.com tab.How can I search selected word existing Dictionary.com tab?
MaxAstro
Posts: 551
Joined: 05 Oct 2016, 13:00

Re: How can I search selected word from existing Dictionary.com tab?

16 Apr 2018, 15:10

Instead of using Run you would have to check if Chrome is open, and if so activate it and switch to the correct tab. Some google searching turned up an old script designed to do that you could tweak as a baseline:

Code: Select all

 chrome := "- Google Chrome"
    found := "false"
    tabSearch := "gmail.com - Gmail"
    curWinNum := 0
    
    SetTitleMatchMode, 2
    
    WinGet, numOfChrome, Count, %chrome% ; Get the number of chrome windows
    
    WinActivateBottom, %chrome% ; Activate the least recent window
    
    WinWaitActive %chrome% ; Wait until the window is active
    
    ControlFocus, Chrome_RenderWidgetHostHWND1 ; Set the focus to tab control ???
    
    ; Loop until all windows are tried, or until we find it
    while (curWinNum < numOfChrome and found = "false") { 
        WinGetTitle, firstTabTitle, A ; The initial tab title
        title := firstTabTitle
        Loop
        {
            if(InStr(title, tabSearch)>0){
                found := "true"
                break
            }
            Send {Ctrl down}{Tab}{Ctrl up}
            Sleep, 50
            WinGetTitle, title, A  ;get active window title
            if(title = firstTabTitle){
                break
            }
        }
        WinActivateBottom, %chrome%
        curWinNum := curWinNum + 1
    }
    
    ; If we did not find it, start it
    if(found = "false"){
        Run "https://gmail.com"
    }
    
    return
Note that this is untested.
my-lord
Posts: 45
Joined: 01 Apr 2018, 15:12

Re: How can I search selected word from existing Dictionary.com tab?

16 Apr 2018, 17:04

MaxAstro wrote:Instead of using Run you would have to check if Chrome is open, and if so activate it and switch to the correct tab. Some google searching turned up an old script designed to do that you could tweak as a baseline:

Code: Select all

 chrome := "- Google Chrome"
    found := "false"
    tabSearch := "gmail.com - Gmail"
    curWinNum := 0
    
    SetTitleMatchMode, 2
    
    WinGet, numOfChrome, Count, %chrome% ; Get the number of chrome windows
    
    WinActivateBottom, %chrome% ; Activate the least recent window
    
    WinWaitActive %chrome% ; Wait until the window is active
    
    ControlFocus, Chrome_RenderWidgetHostHWND1 ; Set the focus to tab control ???
    
    ; Loop until all windows are tried, or until we find it
    while (curWinNum < numOfChrome and found = "false") { 
        WinGetTitle, firstTabTitle, A ; The initial tab title
        title := firstTabTitle
        Loop
        {
            if(InStr(title, tabSearch)>0){
                found := "true"
                break
            }
            Send {Ctrl down}{Tab}{Ctrl up}
            Sleep, 50
            WinGetTitle, title, A  ;get active window title
            if(title = firstTabTitle){
                break
            }
        }
        WinActivateBottom, %chrome%
        curWinNum := curWinNum + 1
    }
    
    ; If we did not find it, start it
    if(found = "false"){
        Run "https://gmail.com"
    }
    
    return
Note that this is untested.
Thanks.I changed script like this but every time this script create new window even though browser has specified TAB.(We have to use send clipboard specified text at the beginning of the script because we don't want to search previous selected text )

Code: Select all

^+d:: 
    chrome := "- Google Chrome"
    Send ^c
    found := "false"
    tabSearch := "http://www.dictionary.com/browse/%clipboard%"
    curWinNum := 0
    
    SetTitleMatchMode, 2
    
    WinGet, numOfChrome, Count, %chrome% ; Get the number of chrome windows
    
    WinActivateBottom, %chrome% ; Activate the least recent window
    
    WinWaitActive %chrome% ; Wait until the window is active
    
    ControlFocus, Chrome_RenderWidgetHostHWND1 ; Set the focus to tab control ???
    
    ; Loop until all windows are tried, or until we find it
    while (curWinNum < numOfChrome and found = "false") { 
        WinGetTitle, firstTabTitle, A ; The initial tab title
        title := firstTabTitle
        Loop
        {

            if(InStr(title, tabSearch)>0){
                found := "true"
                break
            }
            Send {Ctrl down}{Tab}{Ctrl up}
            WinGetTitle, title, A  ;get active window title
            if(title = firstTabTitle){
                break
            }
        }
        WinActivateBottom, %chrome%
        curWinNum := curWinNum + 1
    }
    
    ; If we did not find it, start it
    if(found = "false"){
        Send ^c
		parameter = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe http://www.dictionary.com/browse/"%clipboard%"
		Run %parameter%
    }
    
    return
   
FanaticGuru
Posts: 1194
Joined: 30 Sep 2013, 22:25

Re: How can I search selected word from existing Dictionary.com tab?

16 Apr 2018, 18:27

You might find the Dictionary link in my signature below useful.

It searches Dictionary.com for the word currently highlighted and displays the results in a simplified GUI.

This script is always running on my computer and I use it often.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts

AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon

[Function] Timer - Create and Manage Timers
MaxAstro
Posts: 551
Joined: 05 Oct 2016, 13:00

Re: How can I search selected word from existing Dictionary.com tab?

17 Apr 2018, 08:12

This line is the problem: tabSearch := "http://www.dictionary.com/browse/%clipboard%"

First, to include a variable in a string, you need to do it like this: tabSearch := "http://www.dictionary.com/browse/" . %clipboard%

Secondly, that is going to search for a tab that already has the word you are searching for, which isn't very helpful since it will never be already open. Instead, use tabSearch := "http://www.dictionary.com" to look for an open dictionary.com tab regardless of what word it has open.

Return to “Ask For Help”

Who is online

Users browsing this forum: roysubs, WingbtZ and 37 guests