Page 1 of 1

Scripted paste of image from clipboard

Posted: 20 Jul 2023 13:34
by aubrey97
I often use #206 paste image from clipboard to new png file for documentation
I want to make this more efficient in two respects if anyone can advise

a) I don't want to keep renaming the new created file. Most commonly I would want to name it the same as the currently selected file but with an appended serial number or a date/time. For example I might have a starting file
How to clean a cat.png

If I have that selected I would want the newly created file to be How to clean a cat -01.png or perhaps "how to clean a cat 20230714 1522.png"

Problem is I can't fine any scripted route to using the #206 that will take any optional filename

b) Sometimes pasting to jpg is more efficient for the type of material. I'm aware there is a tweak to change png to jpg pastes. However I don't want a permanent change - rather on the fly.

Many thanks for any helpful pointers or code.

Re: Scripted paste of image from clipboard

Posted: 20 Jul 2023 14:55
by admin
Well, I don't think that's possible at the moment. To make this scriptable I would have to add a new scripting command. I'm not sure if this is justifiable. (I know what you are thinking. :) )

Re: Scripted paste of image from clipboard

Posted: 20 Jul 2023 15:21
by highend
Get e.g. nircmd (http://www.nirsoft.net/utils/nircmd.html) and use a script...

Code: Select all

    $nircmd = "D:\Users\highend\Downloads\nircmd-x64\nircmdc.exe";

    $new  = <curpath> . "\" . gpc(<curitem>, "base") . " " . now("yyyymmdd hhnn") . ".png";
    runret(lax("$nircmd" clipboard saveimage "$new"));
Switching on the fly between jpg and png in XY isn't possible and if you want jpg instead of png from nircmd, look for a cli tool to convert it and add it to the script (e.g. imagemagick).

Re: Scripted paste of image from clipboard

Posted: 20 Jul 2023 17:53
by zakhar
aubrey97 wrote: 20 Jul 2023 13:34 I often use #206
Hello, Dear XYplorer Community!
Hello, aubrey97!

I was interested, if I can find a solution to the problem previously mentioned here on "20 Jul 2023 13:34" under a) by using XY-Scripting.
Therefore I composed a following simple script running under XY v. 24.60.0104:
(it is assumed, that
1. the user has a screenshot in the clipboard,
2. there may be only one file Clipboard-*.png - that one created by #206; - in the current path,
3. before starting the script, the user selects a file the name of which will be used to rename after):

Code: Select all

 $s_i = <selitem>;
 if($s_i == ""){
    echo "No file selected";
    end 1==1;
 }
 $c_p = <curpath>;
 #206;
 $qs1 = quicksearch("Clipboard-*.png /fn",$c_p);
 if($qs1 == ""){
    echo "No file found";
    end 1==1;
 }
 $n_b = gpc($s_i,"base");
 $n_n = $n_b."-"."<date yyyy.mm.dd-hh.MM.ss>".".png";
 renameitem($n_n,$qs1);
The result is a partially unexpected one -
- XY stops on a ready for manual renaming Clipboard-file name and the status bar shows the expected new file name
see attached screenshot.
screenshot.jpg
screenshot.jpg (41.46 KiB) Viewed 1452 times
Then I press "Esc" and XY releses the renamed file with the expected file name.
Expected behavior were only "XY releses the renamed file with the expected file name".

(The information provided above is experimental. I catch screenshots by using other software.)
Edit: grammar.

Re: Scripted paste of image from clipboard

Posted: 21 Jul 2023 02:17
by jupe
@aubrey97: With Irfanview you can on the fly switch between png jpg too, eg

i_view64.exe /clippaste /convert=filename.jpg

@zakhar: #206 waits for input, so you need to skip that somehow, maybe something like this:

Code: Select all

 $base = <curbase>;
 #206; #485;
 if ($base && $base != <curbase>) { renameitem($base,, 17); }

Re: Scripted paste of image from clipboard

Posted: 21 Jul 2023 09:43
by admin
I enhanced SC savethumb to support the clipboard as source. Next beta. :cup:

Re: Scripted paste of image from clipboard

Posted: 21 Jul 2023 13:24
by aubrey97
Many thanks for all responses --I will do some experimenting...

Re: Scripted paste of image from clipboard

Posted: 21 Jul 2023 19:31
by zakhar
@jupe:
Thank you!

@aubrey97:
Now with the new beta "v. 24.60.0109 - 2023-07-21 17:26"
- see here viewtopic.php?p=212802#p212802 -
and "savethumb(<clipimg>, "clipboardimage", "100%", , "jpg")"
we have a complete solution of your query of "20 Jul 2023 13:34" and a complete solution for catching screenshots with XY!

@admin:
Thank you! Perfect application and perfect support! :cup:

Re: Scripted paste of image from clipboard

Posted: 22 Jul 2023 19:23
by aubrey97
:)
admin wrote: 21 Jul 2023 09:43 I enhanced SC savethumb to support the clipboard as source. Next beta. :cup: