Page 1 of 1

Modifiying an existing script

Posted: 15 Feb 2023 16:16
by Ysl
Hi

I use this script to open my browser and look for an image with the file name selected in XYplorer

::$item = regexreplace("<curbase>", "[^a-zA-Z]+", " "); open("http://images.google.com/images?q=$item ... ab=wi$item");

But, I am looking for 2 upgrades :

1 Include numbers in search string
2 Exclude some words or link like "google.com" in the search string (with a way to exclude multiple words)

Thank you for your help

Ysl

Re: Modifiying an existing script

Posted: 15 Feb 2023 16:21
by highend
1. No clue what you mean
2. replace / replacelist / regexreplace() them?

Re: Modifiying an existing script

Posted: 03 Mar 2023 16:09
by Ysl
Hi !

1. The search string generated is letters only, no numbers. I would like to have numbers included

2. If the file name is xxx xxxxx xxxx (yyyyyyyyyyy.com).mp3, I would like to know where to input in the script the string to be ignored, in this case, (yyyyyyyyyyy.com) so that the final search string in google would be like this "xxx xxxxx xxxx.mp3"

3 If possible, I would like to be able to input multiple strings to be avoided in the final search string.

Hope it is clearer for you and thank for your help :)

Sorry for my basic english

Re: Modifiying an existing script

Posted: 03 Mar 2023 21:24
by highend

Code: Select all

    $remove = "google.com<crlf>replace_me<crlf>me_too"; // Multiple entries must be "<crlf>"-separated!
    $esc    = "[ ]*(" . replace(regexreplace($remove, "([\\^$.|?*+()\[{])", "\$1"), <crlf>, "|") . ")[ ]*";
    $item   = regexreplace(regexreplace(<curbase>, $esc, " "), "[^a-z0-9]+", " ");
    open "http://images.google.com/images?q=$item&um=1&ie=UTF-8&source=og&sa=N&hl=fr&tab=wi$item";

Re: Modifiying an existing script

Posted: 04 Mar 2023 17:45
by klownboy
That's a good one highend. Good enough to make it a UDC and put it in XY's toolbox.

I was thinking that it may be even more useful (at least to me) if the script run via UDC was able to detect if there was a highlighted portion of a the base filename. Like for example, if I had file with a name of "church in the mountains.jpg", and I highlighted only a portion of that file name, "mountains". Could the script only google the highlighted portion of the filename if there was something highlighted (in this case "mountains"). If nothing is highlighted, it would google the <curbase> as it currently does. Something like the following, but I'm having issues with copying (ctrl-C) the highlighted text within the filename to the clipboard (when using a UDC to run the script). Is there some way within XY of detecting if there is a highlighted /selected text ready for ctrl-C? I don't want to go outside of XY using AHK. Thanks.

Code: Select all

 #201;sel; //copy highlight and unselect
 $highlite = <clp>;
 if(gettokenindex($highlite, <curbase>, " ")) {  // ensuring the highlight was part of the base filename and not some other unrelated clipboard contents
   $input = $highlite;}
 else {
   $input = <curbase>;}
 $remove = "[ ]*(google\.com|whatever|something else)[ ]*";$item   = regexreplace(regexreplace($input, $remove, " "), "[^a-z0-9]+", " "); open "http://images.google.com/images?q=$item&um=1&ie=UTF-8&source=og&sa=N&hl=fr&tab=wi$item";

Re: Modifiying an existing script

Posted: 04 Mar 2023 20:13
by highend
Afaik it's not even possible to execute a UDC while in inline rename mode... So you either rely on AHK to do something like this, or ... much easier, do something like that:

Code: Select all

    $remove = "google.com<crlf>replace_me<crlf>me_too"; // Multiple entries must be "<crlf>"-separated!
    $esc    = "[ ]*(" . replace(regexreplace($remove, "([\\^$.|?*+()\[{])", "\$1"), <crlf>, "|") . ")[ ]*";
    $item   = regexreplace(regexreplace(<curbase>, $esc, " "), "[^a-z0-9]+", " ");

    if (strpos($item, " ") != -1) {
        $parts = regexmatches($item, "[^\s]+", <crlf>);
        $menu  = <curbase> . <crlf> . "-" . <crlf> . $parts;
        $sel   = popupmenu($menu, 6:=<crlf>);
        if ($sel) { open "http://images.google.com/images?q=$sel&um=1&ie=UTF-8&source=og&sa=N&hl=fr&tab=wi$sel"; }
    } else {
        open "http://images.google.com/images?q=$item&um=1&ie=UTF-8&source=og&sa=N&hl=fr&tab=wi$item";
    }

Re: Modifiying an existing script

Posted: 04 Mar 2023 21:50
by klownboy
highend wrote: 04 Mar 2023 20:13 Afaik it's not even possible to execute a UDC while in inline rename mode
That would explain my difficulties. Without trying it, I assume that would probably apply to a CTB as well. Anyway, thanks for the popupmenu version. I made another version which assumes you have a word already in the clipboard (i.e., copy to the clipboard before invoking the script), but in the end, that's more work than simply using your popupmenu version. Thanks again.

Re: Modifiying an existing script

Posted: 17 Mar 2023 21:52
by Ysl
Sorry for my late reply, I just wanted to say thank you for the script :)