Request - Searching WO Leaving XY

Discuss and share scripts and script files...
SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Request - Searching WO Leaving XY

Post by SkyFrontier »

Guys,

Is there a way to invoke an input, enter a search term, have it searched by default search engine in a new tab (Firefox, portable; opening a predefined instance if none is found) without bringing he browser to foreground?
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

highend
Posts: 14992
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Request - Searching WO Leaving XY

Post by highend »

I guess not (at least not without an external tool).

run doesn't support a non activated (but still visible) window.
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 14992
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Request - Searching WO Leaving XY

Post by highend »

A (not perfect) approach:

A compiled AutoIT script...

XY part:

Code: Select all

    $stringToSearch = input("Enter search term(s)", , , , , 200, 200);

    $helperApp = "D:\Tools\AutoIt\@Scripts\CallFirefoxSearchEngine\CallFirefoxSearchEngine.exe";
    $firefoxExe = "D:\Users\Highend\Tools\Firefox\App\firefox.exe";
    $searchEngineURL = "https://www.google.com/?#q=";

    run """$helperApp"" ""$firefoxExe"" ""$searchEngineURL"" ""$stringToSearch""";
Change the paths accordingly. My FF is only a half portable version because I use a profiles.ini file but I can call the .exe directly. Don't know if your portable wrapper supports parameters...

What you need as well:
https://addons.mozilla.org/en-US/firefox/addon/mozrepl/

After installing the addon, menu Tools - MozRepl - Start AND [x] Activate on startup

If you want to compile the script yourself (I've left out all config stuff so XY can call it with all necessary parameters)
you need the FF.au3 "library": http://www.thorsten-willert.de/Themen/F ... 3/FF.au3?a

Cons:
- FF is started minimized when not currently running instead of putting it into the background
- Atm only one search term is supported. Feel free to add a while loop if you want to open
multiple tabs with searches

The compiled script:
CallFirefoxSearchEngine.zip

Code: Select all

#NoTrayIcon
#Region
#AutoIt3Wrapper_Icon=CallFirefoxSearchEngine.ico
#AutoIt3Wrapper_Outfile=CallFirefoxSearchEngine.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Res_Comment=Firefox search automation
#AutoIt3Wrapper_Res_LegalCopyright=Highend 2014
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#EndRegion
#include <FF.au3>

If $CmdLine[0] >= 3 Then
    $firefoxExe = $CmdLine[1]
    $searchEngineURL = $CmdLine[2]
    $stringToSearch = $CmdLine[3]

    If NOT WinExists("[CLASS:MozillaWindowClass]") Then
        Run($firefoxExe, "", @SW_MINIMIZE)
        WinWait("[CLASS:MozillaWindowClass]", "", 10)
    EndIf

    _FFConnect()
    If _FFIsConnected() Then
         _FFTabAdd($searchEngineURL & $stringToSearch)
    Else
        MsgBox(0,"Error:", "Can't connect to FireFox!")
    EndIf
Else
    MsgBox(0,"Error:", "3 parameters expected but " & $CmdLine[0] & " were received...")
EndIf
To see the attached files, you need to log into the forum.
One of my scripts helped you out? Please donate via Paypal

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Request - Searching WO Leaving XY

Post by SkyFrontier »

Hello, highend!
Thanks much for the answer!

__FFconnect ==> General Error: timeout: can not connect to Firefox/mozrepl on 127.0.0.1:4242

__FFconnect ==> socket error: -1

Error: cannot connect to firefox!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

highend
Posts: 14992
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Request - Searching WO Leaving XY

Post by highend »

MozRepl 1.1.2 is installed and started?

Worked for me out of the box...
One of my scripts helped you out? Please donate via Paypal

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Request - Searching WO Leaving XY

Post by SkyFrontier »

Installed, restarted, firewall-ruled, paths triple-checked... :roll:
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

highend
Posts: 14992
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Request - Searching WO Leaving XY

Post by highend »

You are creating firewall rules for localhost connections? oO

I just fired up a Win 8.1 vm, copied XY, AutoIt and Firefox over
and... it works...

I added a few things to the script:
- Uses $CmdLineRaw => Search terms like "xy plorer" ends "on each start" are possible
- Uses a .ini file to read the search engine url and the ff path (less entries for the xy script and necessary for $CmdLineRaw to work)
- Starts FF normally and restores the calling XY instance after the window is found (no more minimizing)

Bad that it doesn't work for you ;(

Edit: I sometimes get a "__FFWaitForRepl ==> Error TCPSend / TCPRecv: TCPRecv:-1" error. About 1 of 5 tries.
Maybe I contact the author of FF.au3...
One of my scripts helped you out? Please donate via Paypal

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Request - Searching WO Leaving XY

Post by SkyFrontier »

The firewall intercepted the .exe going out. I played with the few options available, nothing had effect.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

highend
Posts: 14992
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Request - Searching WO Leaving XY

Post by highend »

what happens when you use
telnet 127.0.0.1 4242

from inside a cmd prompt?
One of my scripts helped you out? Please donate via Paypal

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Request - Searching WO Leaving XY

Post by SkyFrontier »

the prompt displays the telnet.exe path again.
no prompts from the firewall, nothing else happens.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

highend
Posts: 14992
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Request - Searching WO Leaving XY

Post by highend »

A successful connection looks like this:
Unbenannt1.png
Sure, MozRepl could be the problem but I doubt it. I've tested it on Win7, 8.1 and Server 2012 R2 with a portable and real installation and didn't have any issues with it.

I guess your system settings are a bit borked (firewall wise).
To see the attached files, you need to log into the forum.
One of my scripts helped you out? Please donate via Paypal

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Request - Searching WO Leaving XY

Post by SkyFrontier »

Hi, highend.
Please give me the updates allowing
"my search" specialized
I realized what was going wrong.
Under TOOLS, I had to activate the .xpi.
Now it's running as intended except for the multi-term support.
Thanks!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

highend
Posts: 14992
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Request - Searching WO Leaving XY

Post by highend »

XY part:

Code: Select all

    $stringToSearch = input("Enter search term(s)", , , , , 200, 200);

    $helperApp = "D:\Tools\AutoIt\@Scripts\CallFirefoxSearchEngine\CallFirefoxSearchEngine.exe";
    run """$helperApp"" $stringToSearch";
The .ini file (which is necessary) contains entries for Firefox and the search engine string that you want to use.
The .exe will complain if it can't find the .ini or any of the two entries in it.

The FF.au3 library which gets included by the script was changed:

Code: Select all

Global $_FF_LOADWAIT_STOP = False ; stop loading after $_FF_LOADWAIT_TIMEOUT
Global $_FF_ERROR_MSGBOX = False ; Shows in compiled scripts error messages in msgboxes
If you want it to compile yourself you should make these changes, too.

au3 script, .ini file and the .exe as one package:
CallFirefoxSearchEngine_v1.01.0.zip
If Firefox needs to be started by the script it's still possible that the first search isn't executed.
It's a timing issue from the FF.au3 library and I guess it's either:
- FF needs to load too many tabs on startup
- MozRepl isn't started fast enough to respond to the query

This could be solved by further modifying the library but my FF is running the whole time so I saw no need to do it...
To see the attached files, you need to log into the forum.
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 14992
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Request - Searching WO Leaving XY

Post by highend »

A small addition:

Code: Select all

    perm $P_FF_LASTSEARCH;

    $P_FF_LASTSEARCH = input("Enter search term(s)", , $P_FF_LASTSEARCH, , , 200, 200);
    if ($P_FF_LASTSEARCH != "") { writepv; }

    $helperApp = "D:\Tools\AutoIt\@Scripts\CallFirefoxSearchEngine\CallFirefoxSearchEngine.exe";
    run """$helperApp"" $P_FF_LASTSEARCH";
I think it's nice to let the script remember it's last search term e.g. for the case that the search couldn't be executed because FF had to be started...
One of my scripts helped you out? Please donate via Paypal

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Request - Searching WO Leaving XY

Post by SkyFrontier »

Awesome, highend.
All is working as expected.
Many thanks!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

Post Reply