Hello, i am new and i try to use calc value but i din't make it to work.
Can someone please show a example how to do this...
If file C:\Users\%username%\Documents\temp\1.txt has value "a" (just letter)
then image1
else image2
Kind regards,
JP
It is currently May 29th, 2023, 10:47 pm
Rainmeter (If FILE EXIST THEN IMAGE 1 ELSE IMAGE 2)
-
- Posts: 8
- Joined: September 5th, 2013, 10:07 pm
-
- Developer
- Posts: 22570
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Rainmeter (If FILE EXIST THEN IMAGE 1 ELSE IMAGE 2)
I don't understand. Are you trying to detect whether the file 1.txt exists, or that it contains the text "a" in it?JPapavas wrote:Hello, i am new and i try to use calc value but i din't make it to work.
Can someone please show a example how to do this...
If file C:\Users\%username%\Documents\temp\1.txt has value "a" (just letter)
then image1
else image2
Kind regards,
JP
-
- Developer
- Posts: 22570
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Rainmeter (If FILE EXIST THEN IMAGE 1 ELSE IMAGE 2)
If your intent is that you want to check that a file called 1.txt is there and contains a letter "a" as the entire text of it, then:
http://docs.rainmeter.net/manual-beta/plugins/quote
http://docs.rainmeter.net/manual-beta/measures/general-options/substitute
http://docs.rainmeter.net/manual-beta/measures/general-options/ifactions
http://docs.rainmeter.net/manual-beta/bangs#SetOption
This is a somewhat unusual use of the Quote plugin, but I really think it is the best way. There is a way to get there with WebParser, but that is going to spit up errors in the log if the file isn't there or doesn't contain an "a", and although the skin will work fine, the errors would annoy me, as it isn't an error, just a perfectly valid "yes / no" binary answer.
With Quote plugin, you are asking it to open the file, and return a random line from it. Since there is only one line in the file, it will always return "a" or nothing... If it is "a", then the Substitute makes it "1", if the file is not there, or does not contain "a" on the only line, then the Substitute makes it "-1". The Calc measure tests for this and sets the ImageName.
Make sure the text file has just a "a" in it, not an "a" and a carriage return.
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
[MeasureFile]
Measure=Plugin
Plugin=QuotePlugin
PathName=#CURRENTPATH#1.txt
UpdateDivider=10
Substitute="a":"1","":"-1"
[MeasureCheck]
Measure=Calc
Formula=[MeasureFile]
IfAboveValue=0
IfAboveAction=[!SetOption MeterOne ImageName "#@#Images\Border10.png"][!UpdateMeter MeterOne][!Redraw]
IfBelowValue=0
IfBelowAction=[!SetOption MeterOne ImageName "#@#Images\Border15.png"][!UpdateMeter MeterOne][!Redraw]
DynamicVariables=1
[MeterOne]
Meter=Image
http://docs.rainmeter.net/manual-beta/measures/general-options/substitute
http://docs.rainmeter.net/manual-beta/measures/general-options/ifactions
http://docs.rainmeter.net/manual-beta/bangs#SetOption
This is a somewhat unusual use of the Quote plugin, but I really think it is the best way. There is a way to get there with WebParser, but that is going to spit up errors in the log if the file isn't there or doesn't contain an "a", and although the skin will work fine, the errors would annoy me, as it isn't an error, just a perfectly valid "yes / no" binary answer.
With Quote plugin, you are asking it to open the file, and return a random line from it. Since there is only one line in the file, it will always return "a" or nothing... If it is "a", then the Substitute makes it "1", if the file is not there, or does not contain "a" on the only line, then the Substitute makes it "-1". The Calc measure tests for this and sets the ImageName.
Make sure the text file has just a "a" in it, not an "a" and a carriage return.
-
- Posts: 8
- Joined: September 5th, 2013, 10:07 pm
Re: Rainmeter (If FILE EXIST THEN IMAGE 1 ELSE IMAGE 2)
Thank you so much, i was reading last night pages and pages...
you always help everyone! i will use it right away!
And i will let you know...
Kind regards,
John P
you always help everyone! i will use it right away!
And i will let you know...
Kind regards,
John P
-
- Posts: 8
- Joined: September 5th, 2013, 10:07 pm
Re: Rainmeter (If FILE EXIST THEN IMAGE 1 ELSE IMAGE 2)
Hello, something is wrong...
--------------------------------------------------------------
[MeasureFile]
Measure=Plugin
Plugin=QuotePlugin
PathName=#CURRENTPATH#1.txt
UpdateDivider=10
Substitute="a":"1","":"-1"
[MeasureCheck]
Measure=Calc
Formula=[MeasureFile]
IfAboveValue=0
IfAboveAction=[!SetOption MeterOne ImageName "#@#Images\nb.png"][!UpdateMeter MeterOne][!Redraw]
IfBelowValue=0
IfBelowAction=[!SetOption MeterOne ImageName "#@#Images\fb.png"][!UpdateMeter MeterOne][!Redraw]
--------------------------------------------------------------------------
P.S. file 1.txt must be in
C:\Users\%username%\Documents\Rainmeter\Skins\Name ?
--------------------------------------------------------------
[MeasureFile]
Measure=Plugin
Plugin=QuotePlugin
PathName=#CURRENTPATH#1.txt
UpdateDivider=10
Substitute="a":"1","":"-1"
[MeasureCheck]
Measure=Calc
Formula=[MeasureFile]
IfAboveValue=0
IfAboveAction=[!SetOption MeterOne ImageName "#@#Images\nb.png"][!UpdateMeter MeterOne][!Redraw]
IfBelowValue=0
IfBelowAction=[!SetOption MeterOne ImageName "#@#Images\fb.png"][!UpdateMeter MeterOne][!Redraw]
--------------------------------------------------------------------------
P.S. file 1.txt must be in
C:\Users\%username%\Documents\Rainmeter\Skins\Name ?
Last edited by JPapavas on September 7th, 2013, 11:04 am, edited 1 time in total.
-
- Rainmeter Sage
- Posts: 5093
- Joined: April 12th, 2012, 9:40 pm
- Location: Cedar Point, Ohio, USA
Re: Rainmeter (If FILE EXIST THEN IMAGE 1 ELSE IMAGE 2)
Yes, that is where the file has to be...
Did you make sure it is formatted as JSMorley said?
The "About" window is a valuable troubleshooting tool.
Did you make sure it is formatted as JSMorley said?
You can also open the "About" window, click on "Skins" tab, and then this skin, to see the value being returned by the measure....
Make sure the text file has just a "a" in it, not an "a" and a carriage return.
...
The "About" window is a valuable troubleshooting tool.
:: My DA Gallery :: Rainmeter DA Gallery :: Rainmeter Workshops :: Rainmeter Documentation :: BBCode Guide ::
-
- Posts: 8
- Joined: September 5th, 2013, 10:07 pm
Re: Rainmeter (If FILE EXIST THEN IMAGE 1 ELSE IMAGE 2)
without "a" char:
measureFile range 0.0 - 1.0 value -1
measurecheck range 0.0 - 1.0 value -1
with "a" char:
measureFile range 0.0 - 1.0 value 1
measurecheck range 0.0 - 1.0 value -1
I see this... if it helps...
image need x and y location?
measureFile range 0.0 - 1.0 value -1
measurecheck range 0.0 - 1.0 value -1
with "a" char:
measureFile range 0.0 - 1.0 value 1
measurecheck range 0.0 - 1.0 value -1
I see this... if it helps...
image need x and y location?
-
- Developer
- Posts: 22570
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Rainmeter (If FILE EXIST THEN IMAGE 1 ELSE IMAGE 2)
You just need DynamicVariables=1 on the [MeasureCheck] measure.
The file 1.txt can be anywhere you want it. Just change the PathName option on the Quote plugin measure.
Code: Select all
[MeasureCheck]
Measure=Calc
Formula=[MeasureFile]
IfAboveValue=0
IfAboveAction=[!SetOption MeterOne ImageName "#@#Images\lightonb.png"][!UpdateMeter MeterOne][!Redraw]
IfBelowValue=0
IfBelowAction=[!SetOption MeterOne ImageName "#@#Images\lightoffb.png"][!UpdateMeter MeterOne][!Redraw]
DynamicVariables=1
-
- Developer
- Posts: 22570
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Rainmeter (If FILE EXIST THEN IMAGE 1 ELSE IMAGE 2)
As an aside, if all you really need to do is check to see if a file exists, then this is a pretty general-purpose way to do that using Lua.
Skin Test.ini:
Lua Test.lua:
The Lua simply gets the path/name of the file you want to check from the variable FileToCheck, and attempts to open the file in read-only mode. If the file "open" works, then the file is there and the measure returns "1". If not, the measure returns "-1". The Calc measure then checks the value of the script measure and does whatever you want it to do.
The advantage to this approach is that you can alternatively have the Lua script do all kinds of things itself. Change text, change images, show or hide meters, disable or enable other measures, anything you want. It could be done via SKIN:Bang() commands from the Lua to the skin, without needing some IFAction from hell in a Calc measure.
It would also be really simple to have the Lua actually read the file contents and parse it looking for some value that you would use as a trigger, in addition to the existence of the file.
The only caveat I would add is that it is important to have some UpdateDivider (even just a couple of seconds) on the script measure. If you are just constantly opening the Test.txt file for reading, it will be hard for some external process that is deleting it to have an opportunity to do so without getting "file is in use" errors from Windows. While you can open and read or change the contents of a file that is open with the 'r' parameter in Lua with some other process, you can't rename or delete it while it is open in Lua.
Skin Test.ini:
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
[Variables]
FileToCheck=#CURRENTPATH#Test.txt
[MeasureFile]
Measure=Script
ScriptFile=#CURRENTPATH#Test.lua
UpdateDivider=5
[MeasureCheck]
Measure=Calc
Formula=[MeasureFile]
IfAboveValue=0
IfAboveAction=[!SetOption MeterCheck Text "File exists."][!UpdateMeter MeterCheck][!Redraw]
IfBelowValue=0
IfBelowAction=[!SetOption MeterCheck Text "File not found."][!UpdateMeter MeterCheck][!Redraw]
DynamicVariables=1
[MeterCheck]
Meter=String
FontSize=14
FontColor=255,255,255,255
SolidColor=60,60,60,255
Padding=5,5,5,5
Antialias=1
Code: Select all
function Update()
local FilePath = SKIN:MakePathAbsolute(SKIN:GetVariable('FileToCheck'))
local FoundFile = io.open(FilePath,'r')
if not FoundFile then
return -1
else
io.close(FoundFile)
return 1
end
end
The advantage to this approach is that you can alternatively have the Lua script do all kinds of things itself. Change text, change images, show or hide meters, disable or enable other measures, anything you want. It could be done via SKIN:Bang() commands from the Lua to the skin, without needing some IFAction from hell in a Calc measure.
It would also be really simple to have the Lua actually read the file contents and parse it looking for some value that you would use as a trigger, in addition to the existence of the file.
The only caveat I would add is that it is important to have some UpdateDivider (even just a couple of seconds) on the script measure. If you are just constantly opening the Test.txt file for reading, it will be hard for some external process that is deleting it to have an opportunity to do so without getting "file is in use" errors from Windows. While you can open and read or change the contents of a file that is open with the 'r' parameter in Lua with some other process, you can't rename or delete it while it is open in Lua.
-
- Posts: 8
- Joined: September 5th, 2013, 10:07 pm
Re: Rainmeter (If FILE EXIST THEN IMAGE 1 ELSE IMAGE 2)
Thank you for the (always) fast help. I can say for sure that this Forum has great support.
Now with your help the final code is this...
-----------------------------------------------------------
[Rainmeter]
Author=JPapavas
Update=1000
[Metadata]
Name=example1
Version=1.0
;End of added Metadata
[App1]
meter=button
buttonimage=a1.png
x=0
y=0
buttoncommand=!execute ["C:\example.exe"]
[App2]
meter=button
buttonimage=a2.png
x=0
y=17
buttoncommand=!execute ["C:\example.exe"]
[MeasureFile]
Measure=Plugin
Plugin=QuotePlugin
PathName=#CURRENTPATH#a1.txt
UpdateDivider=5
Substitute="1":"1","0":"-1"
[MeasureCheck]
Measure=Calc
Formula=[MeasureFile]
IfAboveValue=0
IfAboveAction=[!SetOption MeterOne ImageName "b1.png"][!UpdateMeter MeterOne][!Redraw]
IfBelowValue=0
IfBelowAction=[!SetOption MeterOne ImageName "b2.png"][!UpdateMeter MeterOne][!Redraw]
DynamicVariables=1
[MeterOne]
Meter=IMAGE
X=15
----------------------------------------------------------------------------------------------
Kind regards,
JPapavas
Now with your help the final code is this...
-----------------------------------------------------------
[Rainmeter]
Author=JPapavas
Update=1000
[Metadata]
Name=example1
Version=1.0
;End of added Metadata
[App1]
meter=button
buttonimage=a1.png
x=0
y=0
buttoncommand=!execute ["C:\example.exe"]
[App2]
meter=button
buttonimage=a2.png
x=0
y=17
buttoncommand=!execute ["C:\example.exe"]
[MeasureFile]
Measure=Plugin
Plugin=QuotePlugin
PathName=#CURRENTPATH#a1.txt
UpdateDivider=5
Substitute="1":"1","0":"-1"
[MeasureCheck]
Measure=Calc
Formula=[MeasureFile]
IfAboveValue=0
IfAboveAction=[!SetOption MeterOne ImageName "b1.png"][!UpdateMeter MeterOne][!Redraw]
IfBelowValue=0
IfBelowAction=[!SetOption MeterOne ImageName "b2.png"][!UpdateMeter MeterOne][!Redraw]
DynamicVariables=1
[MeterOne]
Meter=IMAGE
X=15
----------------------------------------------------------------------------------------------
Kind regards,
JPapavas