Scripted paste of image from clipboard

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
aubrey97
Posts: 55
Joined: 22 Jun 2013 11:27

Scripted paste of image from clipboard

Post 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.

admin
Site Admin
Posts: 60618
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Scripted paste of image from clipboard

Post 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. :) )

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

Re: Scripted paste of image from clipboard

Post 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).
One of my scripts helped you out? Please donate via Paypal

zakhar
Posts: 150
Joined: 08 Sep 2010 21:13

Re: Scripted paste of image from clipboard

Post 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 733 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.
Last edited by zakhar on 21 Jul 2023 15:31, edited 2 times in total.

jupe
Posts: 2805
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Scripted paste of image from clipboard

Post 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); }

admin
Site Admin
Posts: 60618
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Scripted paste of image from clipboard

Post by admin »

I enhanced SC savethumb to support the clipboard as source. Next beta. :cup:

aubrey97
Posts: 55
Joined: 22 Jun 2013 11:27

Re: Scripted paste of image from clipboard

Post by aubrey97 »

Many thanks for all responses --I will do some experimenting...

zakhar
Posts: 150
Joined: 08 Sep 2010 21:13

Re: Scripted paste of image from clipboard

Post 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:

aubrey97
Posts: 55
Joined: 22 Jun 2013 11:27

Re: Scripted paste of image from clipboard

Post by aubrey97 »

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

Post Reply