It is currently September 8th, 2024, 12:19 am

Building a string with text and variables

Get help with creating, editing & fixing problems with skins
User avatar
InterClaw
Posts: 24
Joined: March 30th, 2022, 5:31 pm
Location: Sweden

Building a string with text and variables

Post by InterClaw »

This is probably very simple to accomplish and I'm missing something obvious here, but I'm trying to piece together a string like this:

Code: Select all

variable1=midtext1
variable2=midtext2

String=text[#variable1]moretext[#variable2]evenmoretext
... to get a result like this:
textmidtext1moretextmidtext2evenmoretext

... but can't for the life of me figure out how to do this. I've tried with quotation marks and & signs in between, but it doesn't seem to do what I want it to. I've also checked this, but it doesn't mention concatenating with plain text like I'm trying to here, only with other variables it seems.
User avatar
CodeCode
Posts: 1383
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Building a string with text and variables

Post by CodeCode »

for this you might want to try this:

variable1=midtext1
variable2=midtext2

Code: Select all

[MeterString]
Meter=String
Fontface=calibri
Fontsize=14
text="#variable1# moretext #variable2# evenmoretext"
Using quotes and a standard variable instead of the nested variable you were trying should do the trick. The quotes are to capture the string with spaces in between.
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
InterClaw
Posts: 24
Joined: March 30th, 2022, 5:31 pm
Location: Sweden

Re: Building a string with text and variables

Post by InterClaw »

CodeCode wrote: April 6th, 2022, 9:28 am

Code: Select all

text="#variable1# moretext #variable2# evenmoretext"
Yep, that sure did the trick.
  • Quotes around the whole string only (if whitespaces are needed, otherwise fine without)
  • No characters for concatenating
  • Use #standard# variables instead
Thank you! Learned something new today. :thumbup:
User avatar
CodeCode
Posts: 1383
Joined: September 7th, 2020, 2:24 pm
Location: QLD, Australia

Re: Building a string with text and variables

Post by CodeCode »

Glad it helped. :thumbup:
ƈǟռ'ȶ ʄɨӼ ɨȶ ɨʄ ɨȶ ǟɨռ'ȶ ɮʀօӄɛ - ʊռʟɛֆֆ ɨȶ ɨֆ ɨռ ƈօɖɛ.
User avatar
balala
Rainmeter Sage
Posts: 16499
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Building a string with text and variables

Post by balala »

CodeCode wrote: April 6th, 2022, 9:28 am Using quotes and a standard variable instead of the nested variable you were trying should do the trick. The quotes are to capture the string with spaces in between.
Sorry, you're mistaken. Quotes are never required in options.
InterClaw wrote: April 6th, 2022, 9:19 am This is probably very simple to accomplish and I'm missing something obvious here, but I'm trying to piece together a string like this:

Code: Select all

variable1=midtext1
variable2=midtext2

String=text[#variable1]moretext[#variable2]evenmoretext
... to get a result like this:
textmidtext1moretextmidtext2evenmoretext
Does perfectly works, supposing the variable1 and variable2 are defined in the [Variables] section, not in the string meter. Both are working well: the "classic" syntax (String=text#variable1#moretext#variable2#evenmoretext) and the nested syntax (String=text[#variable1]moretext[#variable2]evenmoretext).
My guess is you didn1t define the variables in the [Variables] section. Make sure to define them there.
User avatar
InterClaw
Posts: 24
Joined: March 30th, 2022, 5:31 pm
Location: Sweden

Re: Building a string with text and variables

Post by InterClaw »

balala wrote: April 7th, 2022, 6:09 pm My guess is you didn1t define the variables in the [Variables] section. Make sure to define them there.
I did have the variables under the [Variables] section.

But to be honest, this is not a String option, it's for a URL option in a WebParser measure. I just didn't think that would matter, so I kept my question simple.

This does not work for some reason:
URL=http://[#host]:[#port]/something/something/something/darkside

But this does: :confused:
URL=http://#host#:#port#/something/something/something/complete
User avatar
balala
Rainmeter Sage
Posts: 16499
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Building a string with text and variables

Post by balala »

InterClaw wrote: April 7th, 2022, 6:32 pm But this does: :confused:
URL=http://#host#:#port#/something/something/something/complete
It's good if it is working as expected. :thumbup:
Legwind
Posts: 1
Joined: July 17th, 2024, 5:23 am

Re: Building a string with text and variables

Post by Legwind »

Hi all,
I'm new to Rainmeter.
I'm trying to make a skin to show me my session ID, and all other session ID's. This will be great for using on a Windows Server.
However, its not working. Code below:

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=0,0,0,150

[Metadata]
Name=SessionIDs
Author=Based on User's Template
Information=Displays current session IDs.
Version=1.0.0

[MeasureSessionID]
Measure=Plugin
Plugin=RunCommand
Parameter=cmd /c "for /f \"tokens=3\" %i in ('query session ^| findstr /R /C:\"^>.*$\"') do @echo %i"
OutputType=ANSI
DynamicVariables=1
UpdateDivider=1
FinishAction=[!UpdateMeter MeterSessionID][!Redraw]

[MeterSessionID]
Meter=String
MeasureName=MeasureSessionID
FontSize=20
FontColor=255,255,255,255
SolidColor=0,0,0,255
Padding=5,5,5,5
AntiAlias=1
Text="Current Session ID: %1"
All I get is "Current Session ID:"
Please help!
Last edited by Yincognito on July 17th, 2024, 9:50 am, edited 1 time in total.
Reason: To post code, select it and click the </> button above the message box.
User avatar
Yincognito
Rainmeter Sage
Posts: 8030
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Building a string with text and variables

Post by Yincognito »

Legwind wrote: July 17th, 2024, 5:28 am However, its not working. Code below:
[...]
All I get is "Current Session ID:"
Assuming your command line is correct and produces the desired output (running it in CMD is a good way to test that), take a look at the note here, as it explains why it happens and how to solve it:
https://docs.rainmeter.net/manual/plugins/runcommand/#Run

If you want it done on skin load / refresh time, you can use the above in the [Rainmeter] section of your skin, through:
https://docs.rainmeter.net/manual/skins/rainmeter-section/#OnRefreshAction
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16499
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Building a string with text and variables

Post by balala »

Legwind wrote: July 17th, 2024, 5:28 am All I get is "Current Session ID:"
Besides Yincognito's considerations, there are a few thing which definitely should be taken into account:
  • I strongly doubt the Parameter option of the [MeasureSessionID] measure is correct and can work. I'm saying this because:
    • cmd (the first element of the above mentioned Parameter option) is the name of the program you're trying to run the command in. It is the cmd.exe app of the Windows environment. But you don't have to specify this name if you want to run the command, maybe only on the Program option (but finally not even there). So I'd suggest to remove this parameter. If you do this, the Parameter options gets this form: Parameter=/c "for /f \"tokens=3\" %i in ('query session ^| findstr /R /C:\"^>.*$\"') do @echo %i".
    • Maybe I am missing something (definitely might be), but a cmd command line starting with a /c parameter, well, I strongly doubt it'll work. Once again, I might miss something, but this is my guess at least.
  • Even if everything above is alright and the command line can be executed and when executed it gives a proper result, the problem with the above [MeasureSessionID] measure is that it is never executed. There simply is no bang, to get the measure ran. You have to use such a bang, either on a LeftMouseUpAction option (in which case the bang is ran on a click to the meter you've added the bang to), or onto the OnRefreshAction option of the [Rainmeter] section (also suggested by Yincognito, in this case the measure is ran right after you refresh the skin). So for instance add the following option to the [Rainmeter] section of the code: OnRefreshAction=[!CommandMeasure "MeasureSessionID" "Run"].
The last point is the most important. By this, you make sure the command is executed. So for first, add please the above OnRefreshAction option as described above and refresh the skin. Do you get any result?