It is currently April 25th, 2024, 4:50 pm

Advanced modification of existing (jmorley's )script.

Get help with creating, editing & fixing problems with skins
mochibear
Posts: 45
Joined: June 3rd, 2014, 11:16 pm

Advanced modification of existing (jmorley's )script.

Post by mochibear »

EDIT: oops I posted this too soon. It is now complete 8:48 PST.

Firstly, a very special thanks to Jeffrey Morley for creating this script in the first place, as my current workflow would NOT be possible without you. I salute you!

Secondly, I must confess this is a very specialized task that I think only I will benefit from. With that said, this is really a big deal for me, so if anyone can help it will be greatly appreciated!

A little background:
I use an app called Listacular on iOS to create plaintext (.txt) to-do entries for myself, displayed using a Rainmeter script on my 2nd monitor at home. Listacular has the unique ability to popup push notification based on entries that have the following suffixes: @remind(2015-03-25 08:23 (example)
See pic: Image

The problem is, it is incredibly distracting/cluttering to see @remind... and the data/time. Is there any way to tell Rainmeter to hide everything after "@" FOR THAT LINE ONLY .?

So I would like to see this instead
Image


Here's the code and LUA file to work with:

Code: Select all

[Rainmeter]
Author=Jeffrey Morley
Update=1000
DynamicWindowSize=1

[MeasureLuaScript]
Measure=Script
ScriptFile="#CURRENTPATH#SevDesktopSchedule.lua"
FileToRead="D:\Dropbox\SevLists\Schedule.txt"

[MeterDisplay]
Meter=String
MeasureName=MeasureLuaScript
W=300
H=900
FontFace=Segoe UI
FontSize=11
FontColor=255,255,0
SolidColor=0,0,0,1
AntiAlias=1
ClipString=1
 

Code: Select all

function Initialize()

	sFileToRead = SELF:GetOption('FileToRead')
	
end

function Update()

	hReadingFile = io.open(sFileToRead)
	if not hReadingFile then
		print('LuaTextFile: unable to open file at ' .. sFileToRead)
		return
	end
	
	sAllText = hReadingFile:read("*all")
	
	sAllText = string.gsub(sAllText, "\t", "     ")
	
	io.close(hReadingFile)
	
	return tostring(sAllText)	
	
end



Thank you again for reading and trying to help out! I believe I have found the near-perfect GTD-hacked/inspired workflow organization for my life and this is the final kink I need to work out.
User avatar
balala
Rainmeter Sage
Posts: 16169
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Advanced modification of existing (jmorley's )script.

Post by balala »

For sure this is not the best solution, but this is all I could figure out right now.
So, I modified a bit your lua script:

Code: Select all

function Initialize()
   sFileToRead = SELF:GetOption('FileToRead')
end

function Update()
   hReadingFile = io.open(sFileToRead)
   if not hReadingFile then
      print('LuaTextFile: unable to open file at ' .. sFileToRead)
      return
   end
   sAllText = hReadingFile:read("*all")
   sAllText = string.gsub(sAllText, "\t", "     ")
   io.close(hReadingFile)
   SKIN:Bang('!SetVariable', 'Res', tostring(sAllText))
end
This way the script will return its value using the Res variable into the skin.
Then on the skin I added these measures:

Code: Select all

[MeasureStr1]
Measure=String
String=#Res#
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)":"\1","(.*) @(.*)":"\1"

[MeasureStr2]
Measure=String
String=#Res#
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)":"\2","(.*) @(.*)":"\1"

[MeasureStr3]
Measure=String
String=#Res#
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)":"\3","(.*) @(.*)":"\1"

[MeasureStr4]
Measure=String
String=#Res#
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)":"\4","(.*) @(.*)":"\1"

[MeasureStr5]
Measure=String
String=#Res#
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)":"\5","(.*) @(.*)":"\1"

[MeasureStr6]
Measure=String
String=#Res#
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)":"\6","(.*) @(.*)":"\1"

[MeasureStr7]
Measure=String
String=#Res#
DynamicVariables=1
RegExpSubstitute=1
Substitute="^(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)":"\7","(.*) @(.*)":"\1"
and modified the [MeterDisplay] meter to:

Code: Select all

[MeterDisplay]
Meter=String
MeasureName=MeasureStr1
MeasureName2=MeasureStr2
MeasureName3=MeasureStr3
MeasureName4=MeasureStr4
MeasureName5=MeasureStr5
MeasureName6=MeasureStr6
MeasureName7=MeasureStr7
W=300
H=400
SolidColor=0,0,0,100
FontFace=Segoe UI
FontSize=11
FontColor=255,255,0
SolidColor=0,0,0,1
AntiAlias=1
Text=%1#CRLF#%2#CRLF#%3#CRLF#%4#CRLF#%5#CRLF#%6#CRLF#%7
ClipString=1
DynamicVariables=1
Once again, somebody with more lua knowledge will find a simpler and better solution, but maybe you could take a look at this one, too.
FlyingHyrax
Posts: 232
Joined: July 1st, 2011, 1:32 am
Location: US

Re: Advanced modification of existing (jmorley's )script.

Post by FlyingHyrax »

I believe it you can do it by adding this in the Update() function of the lua script, after the other string.gsub call:

sAllText = string.gsub(sAllText, "@remind%(.-%)", "")

You could also accomplish this in the skin instead of the script with a RegExpSubstitute option on the script measure, though the pattern would look a bit different (Lua patterns are not PCRE).
Flying Hyrax on DeviantArt
mochibear
Posts: 45
Joined: June 3rd, 2014, 11:16 pm

Re: Advanced modification of existing (jmorley's )script.

Post by mochibear »

Thank you to both of you!

FlyingHyrax, that seemed to work beautifully. I can even put text after the ignored entries on the same line and it displays it too!

Thank you both so much!
mochibear
Posts: 45
Joined: June 3rd, 2014, 11:16 pm

Re: Advanced modification of existing (jmorley's )script.

Post by mochibear »

Along those same lines, may I request two more minor modifications?


(1)
I want Rainmeter to display anything between two stars (whether there's a space there or not) to be bolded. For example:

** THIS SHOULD BE BOLDED **
**THIS SHOULD BE BOLDED**
* THIS WOULD NOT BE BOLDED **


(2)
If there is a dash at the beginning of the line, Rainmeter will not display it.

For example:

The text file will contain

-Example1
- Example2


Rainmeter will display
Example1
Example2



Thank you in advance guys. This has helped my workflow so incredibly so!
FlyingHyrax
Posts: 232
Joined: July 1st, 2011, 1:32 am
Location: US

Re: Advanced modification of existing (jmorley's )script.

Post by FlyingHyrax »

(2) is pretty simple, if I understand you correctly. You could adjust the script returning the string as follows (using RegExpSubstitute this time, though something similar could be added to the Lua script instead)

Code: Select all

[MeasureLuaScript]
Measure=Script
ScriptFile="#CURRENTPATH#SevDesktopSchedule.lua"
FileToRead="D:\Dropbox\SevLists\Schedule.txt"
RegExpSubstitute=1
Substitute="(?m)^\-\s*":""
I'm not sure that (1) is really possible. Rainmeter handles text formatting at the Meter level - each string meter applies font, color, bold, italics, etc. to its entire string. You'd need a String meter for each individual word in the text you want to display.
Flying Hyrax on DeviantArt
mochibear
Posts: 45
Joined: June 3rd, 2014, 11:16 pm

Re: Advanced modification of existing (jmorley's )script.

Post by mochibear »

Your code worked. Thank you!

if anyone can also give some input whether or not #1 is even possible, it's well appreciated.

Thanks for the help so far!
User avatar
balala
Rainmeter Sage
Posts: 16169
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Advanced modification of existing (jmorley's )script.

Post by balala »

As the whole text is included into one single string meter, I don't think there's any solution for this, as you asked for, because you can set the bold style just for the entire string meter. To can do that, you have to divide the text into lines.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Advanced modification of existing (jmorley's )script.

Post by jsmorley »

#1 is just not realistically possible. There is no concept at all of "inline formatting" in a String meter, so you would need a separate String meter for each element that you wanted to be a different color, using relative positioning to get the effect of a single string. Since there is no realistic way to dynamically create or remove meters from a skin, this could really never work with any dynamic string value gotten from something like WebParser or QuotePlugin.

Any attempt to have some Lua code parse the string, brute force create a new skin .ini file, and refresh the skin, is doomed to complexities with "endless loops" that could only be solved with some really hideous Rube Goldberg solution.

The realistic answer is just "no".
User avatar
balala
Rainmeter Sage
Posts: 16169
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Advanced modification of existing (jmorley's )script.

Post by balala »

It's true that dynamicaly can't create meters, but if the number of strings into the Schedule.txt file has a maximum value (I used 7), the #1 can be achived. Returning to my above post, I'd do that this way:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureLuaScript]
Measure=Script
ScriptFile="#@#Test.lua"
FileToRead="#CURRENTPATH#Schedule.txt"

[MeasureStr1]
Measure=String
String=#Res#
DynamicVariables=1
IfMatch=^\*\*(.*)\*\*$
IfMatchAction=!SetOption MeterDisplay1 StringStyle "BOLD"
IfNotMatchAction=!SetOption MeterDisplay1 StringStyle "NORMAL"
RegExpSubstitute=1
Substitute="^(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)":"\1","(.*) @(.*)":"\1","(?m)^\-\s*":""

[MeasureStr2]
Measure=String
String=#Res#
DynamicVariables=1
IfMatch=^\*\*(.*)\*\*$
IfMatchAction=!SetOption MeterDisplay2 StringStyle "BOLD"
IfNotMatchAction=!SetOption MeterDisplay2 StringStyle "NORMAL"
RegExpSubstitute=1
Substitute="^(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)":"\2","(.*) @(.*)":"\1","(?m)^\-\s*":""

[MeasureStr3]
Measure=String
String=#Res#
DynamicVariables=1
IfMatch=^\*\*(.*)\*\*$
IfMatchAction=!SetOption MeterDisplay3 StringStyle "BOLD"
IfNotMatchAction=!SetOption MeterDisplay3 StringStyle "NORMAL"
RegExpSubstitute=1
Substitute="^(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)":"\3","(.*) @(.*)":"\1","(?m)^\-\s*":""

[MeasureStr4]
Measure=String
String=#Res#
DynamicVariables=1
IfMatch=^\*\*(.*)\*\*$
IfMatchAction=!SetOption MeterDisplay4 StringStyle "BOLD"
IfNotMatchAction=!SetOption MeterDisplay4 StringStyle "NORMAL"
RegExpSubstitute=1
Substitute="^(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)":"\4","(.*) @(.*)":"\1","(?m)^\-\s*":""

[MeasureStr5]
Measure=String
String=#Res#
DynamicVariables=1
IfMatch=^\*\*(.*)\*\*$
IfMatchAction=!SetOption MeterDisplay5 StringStyle "BOLD"
IfNotMatchAction=!SetOption MeterDisplay5 StringStyle "NORMAL"
RegExpSubstitute=1
Substitute="^(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)":"\5","(.*) @(.*)":"\1","(?m)^\-\s*":""

[MeasureStr6]
Measure=String
String=#Res#
DynamicVariables=1
IfMatch=^\*\*(.*)\*\*$
IfMatchAction=!SetOption MeterDisplay6 StringStyle "BOLD"
IfNotMatchAction=!SetOption MeterDisplay6 StringStyle "NORMAL"
RegExpSubstitute=1
Substitute="^(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)":"\6","(.*) @(.*)":"\1","(?m)^\-\s*":""

[MeasureStr7]
Measure=String
String=#Res#
DynamicVariables=1
IfMatch=^\*\*(.*)\*\*$
IfMatchAction=!SetOption MeterDisplay7 StringStyle "BOLD"
IfNotMatchAction=!SetOption MeterDisplay7 StringStyle "NORMAL"
RegExpSubstitute=1
Substitute="^(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)\n(.*)":"\7","(.*) @(.*)":"\1","(?m)^\-\s*":""

[MeterDisplay1]
Meter=String
MeasureName=MeasureStr1
W=200
H=20
SolidColor=0,0,0,100
FontFace=Segoe UI
FontSize=11
FontColor=255,255,0
SolidColor=0,0,0,1
AntiAlias=1
Text=%1
ClipString=1
DynamicVariables=1

[MeterDisplay2]
Meter=String
MeasureName=MeasureStr2
X=0r
Y=0R
W=200
H=20
SolidColor=0,0,0,100
FontFace=Segoe UI
FontSize=11
FontColor=255,255,0
SolidColor=0,0,0,1
AntiAlias=1
Text=%1
ClipString=1
DynamicVariables=1

[MeterDisplay3]
Meter=String
MeasureName=MeasureStr3
X=0r
Y=0R
W=200
H=20
SolidColor=0,0,0,100
FontFace=Segoe UI
FontSize=11
FontColor=255,255,0
SolidColor=0,0,0,1
AntiAlias=1
Text=%1
ClipString=1
DynamicVariables=1

[MeterDisplay4]
Meter=String
MeasureName=MeasureStr4
X=0r
Y=0R
W=200
H=20
SolidColor=0,0,0,100
FontFace=Segoe UI
FontSize=11
FontColor=255,255,0
SolidColor=0,0,0,1
AntiAlias=1
Text=%1
ClipString=1
DynamicVariables=1

[MeterDisplay5]
Meter=String
MeasureName=MeasureStr5
X=0r
Y=0R
W=200
H=20
SolidColor=0,0,0,100
FontFace=Segoe UI
FontSize=11
FontColor=255,255,0
SolidColor=0,0,0,1
AntiAlias=1
Text=%1
ClipString=1
DynamicVariables=1

[MeterDisplay6]
Meter=String
MeasureName=MeasureStr6
X=0r
Y=0R
W=200
H=20
SolidColor=0,0,0,100
FontFace=Segoe UI
FontSize=11
FontColor=255,255,0
SolidColor=0,0,0,1
AntiAlias=1
Text=%1
ClipString=1
DynamicVariables=1

[MeterDisplay7]
Meter=String
MeasureName=MeasureStr7
X=0r
Y=0R
W=200
H=20
SolidColor=0,0,0,100
FontFace=Segoe UI
FontSize=11
FontColor=255,255,0
SolidColor=0,0,0,1
AntiAlias=1
Text=%1
ClipString=1
DynamicVariables=1
Test.lua (save it in the @Resources folder):

Code: Select all

function Initialize()
	sFileToRead = SELF:GetOption('FileToRead')
end

function Update()
	hReadingFile = io.open(sFileToRead)
	sAllText = hReadingFile:read("*all")
	sAllText = string.gsub(sAllText, "\t", "     ")
	io.close(hReadingFile)
	SKIN:Bang('!SetVariable', 'Res', tostring(sAllText))
end
Here I used pieces of code taken from FlyingHyrax.