It is currently April 25th, 2024, 5:03 am

Launching external programs?

Share and get help with Plugins and Addons
TheGoodRobot
Posts: 1
Joined: January 18th, 2010, 5:42 am

Launching external programs?

Post by TheGoodRobot »

(:) Hey All,

I'm extremely new to the community and to Rainmeter itself. I'm not sure if this is the correct area to post in, but what the hey.

I have two questions, I suppose.

Firstly, I have been playing around with some of the RSS features that Rainmeter has to offer, but I find it terribly confusing. Could someone point me towards a decent tutorial on the matter?

Secondly, and the reason for posting on this board, in my tinkering with RSS feeds I have managed to dabble into the sunrise/sunset config that comes prepackaged with Enigma. However, I have larger goals in mind. I really want to have a config ask the respected server for the sunrise/sunset times and then do one of two things. If(time ==sunset), I want it to either launch another program to change the desktop wallpaper of my computer, or do it itself, and If(time ==sunrise) - switch it back to it's original wallpaper.

(I'm sure you can see where I am going with this, have the wallpaper display a nighttime sky or a daytime sky)

I'm not even sure if this is possible, but if anyone can point me in the right direction, it would be most appreciated. If I can't do this using Rainmeter, I am pretty confident that I can using C#.

Thank you in advance,

-TheGoodRobot
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Launching external programs?

Post by jsmorley »

You can use a couple of features of Rainmeter to help with this, but will need some kind of external program to bring it home.

1) You can use a WebParser measure to get the time of "sunset" If you want precision, you are going to need two measures, one to get the hour in 24-hour format and one the minutes. Then you will need to get the current time the same way.
2) You can use some fairly complicated Calc measures to multiply the hours by sixty and add to the minutes and compare the sunset time with the current time and use !Execute= ["external app" "parameter"] to call an external program that changes your wallpaper.

Probably not a trivial exercise, but might be fun.

Another option is to just get the sunset hours / minutes from WebParser and pass them as parms to a C# program that would use that along with the current time to do the comparison (the string / number comparisons and action forks based on it will be a bunch easier in C than in Rainmeter) and set the wallpaper yourself in the C# program. (it's an easy call to user32.dll) You can use FinishAction= in the WebParser measure to call the C# program.

If you are new to Rainmeter this is going to sound like the old Steve Martin joke "How to have a million dollars and not pay ANY taxes." "First, get a million dollars..." If you want to tackle it though, there are folks here like Alex and Kenz0 and I that can pitch in and help with getting you going.
User avatar
psouza4
Developer
Posts: 30
Joined: December 2nd, 2010, 1:56 pm
Location: Meridian, ID, USA

Re: Launching external programs?

Post by psouza4 »

There's also the possibility of writing your own plugin in C# and having a skin refer to it as a .dll, so that no external programs are called. You have several options really, depending on what factors are most important to you.
User avatar
GhostMatrix
Rainmeter Sage
Posts: 141
Joined: April 18th, 2009, 8:26 pm
Location: Montreal, Quebec, Canada 45.5658°N, 73.5898°W UTC -5

Re: Launching external programs?

Post by GhostMatrix »

Hi TheGoodRobot!
I'm not even sure if this is possible, but if anyone can point me in the right direction, it would be most appreciated.
yes it's possible!!


Wallpaper
I want it to either launch another program to change the desktop wallpaper of my computer
I already doing this with Rainmeter...
You will find some applications for that, but when you run them you will have a DOS window to pop up for a second or two.
I hate DOS window pop up!!

I use Nircmd for that ,great application for Rainmeter...
http://www.nirsoft.net/utils/nircmd.html
(Download Links at the bottom of the page)
If(time ==sunset) - change the desktop wallpaper of my computer and If(time ==sunrise) - switch it back to it's original wallpaper.
I also already doing (not finish) something similar to the if(time ==sunset) but with more current sky conditions like Astronomical twilight starts, Nautical twilight starts, Civil twilight starts, etc, but it not involving Wallpaper.
I have managed to dabble into the sunrise/sunset config that comes prepackaged with Enigma.
So I assume you're using Enigma.
The instructions in the code below is related to the Sun.ini of Enigma.
I just apply what I have done for my skins to Enigma, if your're not using Enigma it could be a different story, like the RegExp= for an example.
English is not my native language (French Canadian), you may find misspelled words, wrong conjugation, etc..., I just hope you will understand what I'm trying to explain.


Couple of things before the How to...
Work on Windows XP SP3, don't know for Windows Vista or Seven.
On XP your desktop has to be set for "show desktop icons" (Active Desktop disabled).
Only works with .bmp files, you need to convert a .jpg or .png files into bmp.
Actions are delayed due to the Update=10000 of the Sun.ini of Enigma skin, it will take a couple of secondes for the sunrise and sunset time to appear, or get the new wallpaper when your clock reach the sunrise or sunset time.

Code: Select all

I use the NirCmd Commands (regsetval [type] [key] [value name] [value])* to set the Wallpaper value in the Windows Registry.
*Writes a value to the Registry. the [type] parameter can be "sz" or "expand_sz" for strings, "dword" for 32-bit number, or "binary" for binary data.

In my case
[C:\Ressources\nircmd\nircmd.exe regsetval sz "HKCU\Control Panel\Desktop" "Wallpaper" "C:\Wallpapers\Alienware.bmp"]

C:\Ressources\nircmd\nircmd.exe = [path of the nircmd.exe]
regsetval = [nircmd Command]
sz = [type]
"HKCU\Control Panel\Desktop" = [key]
"Wallpaper" = [value name]
"C:\Wallpapers\Alienware.bmp" = [value]

That it for the Nircmd part!

Now I have set a new value for the Wallpaper in the registry, but I need to update the System Parameter after that with this...  
[RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True]

Those two [...] [...] will be use later on...
---------------------------------------------------------------
Now the Sun.ini of Enigma

You have to add this measure above the [MeasureRise] measure...

[MeasureTimeHM]
Measure=Time
Format="%#I%M" (without the usual : character in the time format)

this will return the 12 hour time like this 247 (2:47 am or pm)
---------------------------------------------------------------
On the [MeasureRise]

Change the name for [MeasureRiseH]

The original RegExp= parse too many values for nothing, change it with this one...  
RegExp="(?siU)sunrise="(.*):(.*)\s.*(.*)".*sunset="(.*):(.*)\s.*(.*)"/>"

This will return the index values of sunrise and sunset separately like this
7
28
am
4
39
pm

Change the 3 in the StringIndex= for 1
Remove Substitute=":":"."

Add
IfAboveValue=0
IfAboveAction=!Execute [!RainmeterEnableMeasure MeasureSunrise][!RainmeterEnableMeasure MeasureSunSet]

This will enable those two measure who are disabled at start to avoid the trigger of the change wallpaper action, because on the initial start of the skin all measures return 0 or null (nothing), and this trigger the change wallpaper action on the initial start.
---------------------------------------------------------------
Delete 
[MeasureSet]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureRise]
StringIndex=4
Substitute=":":"."

Add the following measures...

[MeasureRiseM]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureRiseH]
StringIndex=2

[MeasureRiseAM]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureRiseH]
StringIndex=3

[MeasureSetH]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureRiseH]
StringIndex=4

[MeasureSetM]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureRiseH]
StringIndex=5

[MeasureSetPM]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureRiseH]
StringIndex=6

---------------------------------------------------------------
Now the calculate time formula!

I will assume that you have named your two wallpapers Sunrise.bmp and Sunset.bmp, and they are in the Wallpapers folder in the C Drive. 

Add the following measures...

[MeasureSunrise]
Measure=Calc
Formula=((MeasureRiseH*100 + MeasureRiseM) = MeasureTimeHM) ? (1) : (-1)
IfEqualValue=1
IfEqualAction=!Execute [C:\Ressources\SetWallpaper\SetWallpaper.exe C:\Wallpapers\Sunrise.bmp][RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True]
Disabled=1

[MeasureSunset]
Measure=Calc
Formula=((MeasureSetH*100 + MeasureSetM + 1200) = MeasureTimeHM + 1200) ? (1) : (-1)
IfEqualValue=1
IfEqualAction=!Execute [C:\Ressources\SetWallpaper\SetWallpaper.exe C:\Wallpapers\Sunset.bmp][RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True]
Disabled=1

You wonder what it does?
It take the value of MeasureRiseH and multiplicate it by 100 (to bring the hour value on the same value level of the MeasureTimeHM), and add up the minute value of MeasureRiseM.
The +1200 on the sunset formula add up 1200, to bring the 12-Hour time format to the 24-Hour time format.   
Then it check if it equal the current time of MeasureTimeHM (yes or no)
The ? (1) : (-1) part check the "yes" and "no" result and return a value...
yes will return 1
no will return -1

Well if 1 is the result, it will trigger the two action codes.
---------------------------------------------------------------
Now the Style and Text meters

On the meter [StyleLabel]
remove Text="%1 |"
For unknown reason a new format like "%1:%2 %3|" doesn't work... 

Replace the meter [Sunrise] for this one...

[Sunrise]
Meter=STRING
MeterStyle=StyleText
MeasureName=MeasureRiseH
MeasureName2=MeasureRiseM
MeasureName3=MeasureRiseAM
Text="%1:%2 %3|"

Replace the meter [Sunset] for this one...
   
[Sunset]
Meter=STRING
MeterStyle=StyleText
MeasureName=MeasureSetH
MeasureName2=MeasureSetM
MeasureName3=MeasureSetPM
Text="%1:%2 %3|"
Y=15

That it!!
---------------------------------------------------------------
I hope this will help you to understand Rainmeter a little more, and make you accomplish what you're trying to do!!

GM
If at first you don't succeed; call it version 0.1

Image