It is currently March 28th, 2024, 3:31 pm

Copy file and rename it continuously

Get help with creating, editing & fixing problems with skins
User avatar
zivallh
Posts: 38
Joined: October 16th, 2019, 2:26 pm

Copy file and rename it continuously

Post by zivallh »

Hi All,

Is it possible to copy the downloaded file and rename it continuously like Unsplash01 Unsplash02 Unsplash03, if i make Mouse action to save it

Code: Select all

[Webparser]
Measure=Plugin
Plugin=WebParser
URL=https://source.unsplash.com/random/#SCREENAREAWIDTH#x#SCREENAREAHEIGHT#/
UpdateRate=-1
Download=1
DownloadFile=Unsplash.jpg
FinishAction=!SetWallpaper "DownloadFile\Unsplash.jpg"

LeftMouseUpAction=!Execute ["#SKINSPATH#\UnsplashForRainmeter\DownloadFile"]
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Copy file and rename it continuously

Post by balala »

zivallh wrote: November 10th, 2020, 11:51 am Is it possible to copy the downloaded file and rename it continuously like Unsplash01 Unsplash02 Unsplash03, if i make Mouse action to save it
Yep, it definitely is. You have to use a RunCommand plugin measure. But there is an issue: you can't use a LeftMouseUpAction option on a measure, just on a meter (you did use it on the [Webparser] measure). It doesn't work on measures, so I did the copying a little bit differently. Whenever the [Webparser] measure downloads a new image, it is copied to the appropriate location. If this is not exactly what you want, let me know to modify the code.
So, here is my approach. Add the following measure to your code:

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=copy "[Webparser]" "#Path#\Unsplash#Count#.jpg"
State=Hide
DynamicVariables=1
Note that in this measure the file is copied to to the location defined into the Path variable, within the [Variables] section. You have to add it there. It is the path of the folder (not addint the file name as well) where you want to copy the image. For instance:

Code: Select all

[Variables]
Path=d:
With this variable, the images will be copied as d:\Unsplash02.jpg, d:\Unsplash03.jpg and so on. Obviously you can modify the path as you want.
There is another measure you have to add. Add the following one as well:

Code: Select all

[MeasureCount]
Measure=Calc
Formula=( MeasureCount + 1 )
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(.)$":"0\1"
OnChangeAction=[!SetVariable Count "[MeasureCount]"][!WriteKeyValue Variables Count "[MeasureCount]"][!UpdateMeasure "MeasureRun"]
UpdateDivider=-1
See that you get never updated this measure (except the very first moment, after you refresh / load the skin), due to its UpdateDivider=-1 option. We gonna update this measure whenever the WebParser measure downloads a new image.
Replace the FinishAction option of the [Webparser] measure with the following one: FinishAction=[!SetWallpaper "DownloadFile\Unsplash.jpg"][!UpdateMeasure "MeasureCount"][!CommandMeasure "MeasureRun" "Run"]. Every time the measure downloads an image, these bangs are executed, so the !SetWallpaper bang sets the wallpaper, the !UpdateMeasure bang updates the [MeasureCount] measure, increasing its value by one and finally[Youtube][/Youtube] the !CommandMeasure bang runs the [MeasureRun] measure (posted above). Since the value of the [MeasureCount] measure is updated by the above FinishAction option, it changes, so the [!SetVariable Count "[MeasureCount]"] bang sets a new value for the Count variable, the [!WriteKeyValue Variables Count "[MeasureCount]"] bang writes this value into the [Variables] section and the [!UpdateMeasure "MeasureRun"] bang updates the [MeasureRun] measure, in order to let it to use the new value of the variable.
You also have to remove one option: the UpdateRate=-1 option of the [Webparser] measure doesn't seem to be alright. If you use it, you never get update this measure, so it never downalods a new image, after you get downloaded the first. I'd remove it.
The above procedure has a great disadvantage: if you refresh the skin, you get the counting of the Count variable form the begining, you the first images will be rewritten. Please let me know if you want to countinue the counting, to keep all previously downloaded image (which I suppose), because such in a case we have to modify a little bit the above procedure. It probably is possible, but I didn't do it so far, waiting first you to test it and let me know how does it work, if it is alright.
User avatar
zivallh
Posts: 38
Joined: October 16th, 2019, 2:26 pm

Re: Copy file and rename it continuously

Post by zivallh »

Thank you Laszlo,

I have changed the code it's working perfect, but it saves each image it load, I want if I save it by action?

on more thing if I don't want to change the wallpaper on Refresh is that possible ? by adding something like this

Code: Select all

 OnRefreshAction=[!CommandMeasure Webparser "Stop"] 

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
BackgroundMode=2
SolidColor=0,0,0,1
DynamicWindowSize=1

ContextTitle=Setting
ContextAction=[!ActivateConfig "UnsplashForRainmeter\Setting"]

[Variables]
Scale=1
Path=D:\

[Webparser]
Measure=Plugin
Plugin=WebParser
URL=https://source.unsplash.com/random/#SCREENAREAWIDTH#x#SCREENAREAHEIGHT#/
UpdateRate=-1
Download=1
DownloadFile=Unsplash.jpg
FinishAction=[!SetWallpaper "DownloadFile\Unsplash.jpg"][!UpdateMeasure "MeasureCount"][!CommandMeasure "MeasureRun" "Run"]

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=copy "[Webparser]" "#Path#\Unsplash#Count#.jpg"
State=Hide
DynamicVariables=1

[MeasureCount]
Measure=Calc
Formula=( MeasureCount + 1 )
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(.)$":"0\1"
OnChangeAction=[!SetVariable Count "[MeasureCount]"][!WriteKeyValue Variables Count "[MeasureCount]"][!UpdateMeasure "MeasureRun"]
UpdateDivider=-1

[Background]
Meter=Shape
Shape=Rectangle 0,0,(160*#Scale#),(45*#Scale#),6 | StrokeWidth 0 | StrokeColor 0,0,0 | Fill Color 60,231,137,0
Shape2=Rectangle (80*#Scale#),0,(80*#Scale#),(45*#Scale#),6 | StrokeWidth 0 | Fill LinearGradient Grad
Grad=180 | 255,255,255,0 ; 0.1 | 255,255,255,100 ; 1
LeftMouseUpAction=[!CommandMeasure Webparser Update][!Redraw]
MiddleMouseDownAction=!Execute ["#SKINSPATH#\UnsplashForRainmeter\DownloadFile"]
DynamicVariables=1

[Unsplash]
Meter=String
Text=Unsplash
FontFace=Gilroy ExtraBold
FontSize=(14*#Scale#)
X=(15*#Scale#)
Y=(22.5*#Scale#)
StringStyle=Normal
StringAlign=LeftCenter
AntiAlias=1
FontColor=255,255,255

[Next]
Meter=Image
ImageName=#@#Images/Next.png
X=(125*#Scale#)
Y=(12*#Scale#)
W=(20*#Scale#)
DynamicVariables=1
Last edited by zivallh on November 11th, 2020, 8:44 am, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Copy file and rename it continuously

Post by balala »

zivallh wrote: November 11th, 2020, 6:21 am I have changed the code but it's stop working and it's not saving the pictures maybe something wrong,
What the "it's stop working" does mean? The skin doesn't copy the images but does it download them? To make sure it downloads the images, add the following simple Image meter, to the end of the code, to see the current image:

Code: Select all

[Image]
Meter=Image
MeasureName=Webparser
X=0
Y=0
W=400
H=300
PreserveAspectRatio=1
Does the above meter show the image? It does for me, so I say it should for you as well, but is this correct? Do you see the image?
Also does the skin set the wallpaper?
zivallh wrote: November 11th, 2020, 6:21 am on more thing if I don't want to change the wallpaper on Refresh is that possible ? by adding something like this

Code: Select all

 OnRefreshAction=[!CommandMeasure Webparser "Stop"] 
Let's get the skin working for first, then we'll take care of this as well.
User avatar
zivallh
Posts: 38
Joined: October 16th, 2019, 2:26 pm

Re: Copy file and rename it continuously

Post by zivallh »

Sorry it working I just quite Rainmeter and re open it again, but it saves each image it load, we can make it by action if I do save, and there is another thing if I refresh the skin it save over the old ones over
User avatar
zivallh
Posts: 38
Joined: October 16th, 2019, 2:26 pm

Re: Copy file and rename it continuously

Post by zivallh »

I've move the code to Next button to save only the images that I want, only the over save after refresh

Code: Select all

[Next]
Meter=Image
ImageName=#@#Images/Next.png
X=(125*#Scale#)
Y=(12*#Scale#)
W=(20*#Scale#)
LeftMouseUpAction=[!UpdateMeasure "MeasureCount"][!CommandMeasure "MeasureRun" "Run"]
DynamicVariables=1
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Copy file and rename it continuously

Post by balala »

zivallh wrote: November 11th, 2020, 11:49 am I've move the code to Next button to save only the images that I want, only the over save after refresh
So does it work now as expected? Sorry, but I'm not entriely sure.
User avatar
zivallh
Posts: 38
Joined: October 16th, 2019, 2:26 pm

Re: Copy file and rename it continuously

Post by zivallh »

It's works, but when you refresh the skin it's start renaming again from beginning, even if there is images with the same name in the path folder over the old ones
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Copy file and rename it continuously

Post by balala »

zivallh wrote: November 11th, 2020, 6:21 am I have changed the code it's working perfect, but it saves each image it load, I want if I save it by action?
zivallh wrote: November 11th, 2020, 1:39 pm It's works, but when you refresh the skin it's start renaming again from beginning, even if there is images with the same name in the path folder over the old ones
I attach the next release. This code stores the value of the shown image (a number, starting from 1 and growing) and when you refresh ther skin, it continues the previously stored value. To save the image you have to click the image.
I completely removed the setting wallpaper feature (in fact I just commented it out), this code doesn't set it, because I'm not sure when and how would you like to set it. I suppose it's easy to add back such a feature, just please let me know where to add it (what do you want to do, to set the current image as wallpaper)? A right click on the image should set the wallpaper, or alternativelly we should add a Set wallpaper button, or something like this?

Code: Select all

[Variables]
Start=1
Count=0
Path=d:

[Rainmeter]
DynamicWindowSize=1
AccurateText=1

[MeasureCount]
Measure=Calc
Formula=(( #Start# >= 1 ) ? #Count# : ( MeasureCount + 1 - #Start# ))
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(.)$":"0\1"
IfCondition=(#Start#=1)
IfTrueAction=[!Delay "1000"][!SetVariable Start "0"][!UpdateMeasure "#CURRENTSECTION#"]
OnChangeAction=[!SetVariable Count "[MeasureCount]"][!WriteKeyValue Variables Count "[MeasureCount]"][!UpdateMeasure "MeasureRun"]
UpdateDivider=-1

[Webparser]
Measure=Plugin
Plugin=WebParser
URL=https://source.unsplash.com/random/#SCREENAREAWIDTH#x#SCREENAREAHEIGHT#/
UpdateRate=60
Download=1
DownloadFile=Unsplash.jpg
;FinishAction=!SetWallpaper "DownloadFile\Unsplash.jpg"
FinishAction=[!UpdateMeasure "MeasureCount"]
;LeftMouseUpAction=!Execute ["#SKINSPATH#\UnsplashForRainmeter\DownloadFile"]

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=copy "[Webparser]" "#Path#\Unsplash#Count#.jpg"
State=Hide
DynamicVariables=1

[MeterWallpaper]
Meter=Image
MeasureName=Webparser
X=0
Y=0
W=400
H=300
PreserveAspectRatio=1
LeftMouseUpAction=[!CommandMeasure "MeasureRun" "Run"]
User avatar
zivallh
Posts: 38
Joined: October 16th, 2019, 2:26 pm

Re: Copy file and rename it continuously

Post by zivallh »

Thank you so much! :) :great:

This is exactly what I'm looking for, simply to set wallpaper if I like the wallpaper there is a button to save it .

I Have changed the UpdateRate=-1 in Webparser so only if i want to change the wallpaper I click on the button "[Background]"

But should I use the old code or the new one for updating the wallpaper I think both codes can work!

Code: Select all

LeftMouseUpAction=[!CommandMeasure Webparser Update]
LeftMouseUpAction=[!UpdateMeasure "MeasureCount"]

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
BackgroundMode=2
SolidColor=0,0,0,1
DynamicWindowSize=1

ContextTitle=Setting
ContextAction=[!ActivateConfig "UnsplashForRainmeter\Setting"]

;OnRefreshAction=
;[!CommandMeasure Webparser "Stop"]
;[!DisableMeasure Webparser]

[Variables]
Scale=1
Start=1
Count=0
Path=D:\Unsplash

[MeasureCount]
Measure=Calc
Formula=(( #Start# >= 1 ) ? #Count# : ( MeasureCount + 1 - #Start# ))
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(.)$":"0\1"
IfCondition=(#Start#=1)
IfTrueAction=[!Delay "1000"][!SetVariable Start "0"][!UpdateMeasure "#CURRENTSECTION#"]
OnChangeAction=[!SetVariable Count "[MeasureCount]"][!WriteKeyValue Variables Count "[MeasureCount]"][!UpdateMeasure "MeasureRun"]
UpdateDivider=-1

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=copy "[Webparser]" "#Path#\Unsplash#Count#.jpg"
State=Hide
DynamicVariables=1

[Webparser]
Measure=Plugin
Plugin=WebParser
URL=https://source.unsplash.com/random/#SCREENAREAWIDTH#x#SCREENAREAHEIGHT#/
UpdateRate=-1
Download=1
DownloadFile=Unsplash.jpg
FinishAction=[!UpdateMeasure "MeasureCount"][!SetWallpaper "DownloadFile\Unsplash.jpg"]

[Background]
Meter=Shape
Shape=Rectangle 0,0,(160*#Scale#),(45*#Scale#),6 | StrokeWidth 0 | StrokeColor 0,0,0 | Fill Color 60,231,137,0
Shape2=Rectangle (80*#Scale#),0,(80*#Scale#),(45*#Scale#),6 | StrokeWidth 0 | Fill LinearGradient Grad
Grad=180 | 255,255,255,0 ; 0.1 | 255,255,255 ; 1
LeftMouseUpAction=[!CommandMeasure Webparser Update]
MiddleMouseDownAction=!Execute ["#Path#"]
DynamicVariables=1

[Unsplash]
Meter=String
Text=Unsplash
FontFace=Gilroy ExtraBold
FontSize=(14*#Scale#)
X=(15*#Scale#)
Y=(22.5*#Scale#)
StringStyle=Normal
StringAlign=LeftCenter
AntiAlias=1
FontColor=255,255,255
DynamicVariables=1

[Download]
Meter=Image
ImageName=#@#Images/Download.png
ImageRotate=90
X=(125*#Scale#)
Y=(12*#Scale#)
W=(20*#Scale#)
LeftMouseUpAction=[!UpdateMeasure "MeasureCount"][!CommandMeasure "MeasureRun" "Run"]["#Path#"]
DynamicVariables=1

Post Reply