It is currently May 3rd, 2024, 4:47 am

Change image when program closes

Get help with creating, editing & fixing problems with skins
adammjpope
Posts: 2
Joined: February 1st, 2011, 7:03 pm

Change image when program closes

Post by adammjpope »

Just getting to grips with Rainmeter at the moment. I understand how to change an image when the mouse hovers over an icon and also how to change it when the icon is clicked however I would like the image to change when a program is closed. For example I have a button on the desktop which is grey, yellow when hovered over, red when clicked which also opens Open Office. However when I close Open Office I would like the button to revert back to grey. Is this possible?

If anymore information is require please let me know.

Thanks in advance!

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

Re: Change image when program closes

Post by jsmorley »

[MeasureProcessPID]
Measure=Plugin
Plugin=Perfmon.dll
PerfMonObject="Process"
PerfMonCounter="ID Process"
PerfMonInstance="soffice"
PerfMonDifference=0
UpdateDivider=2

[CalcTranslatePIDToRunningState]
Measure=Calc
Formula=MeasureProcessPID > 0 ? 1 : 0

Now you have a measure [CalcTranslatePIDToRunningState] that will be "1" if Open Office is running, and "0" if not.

There are a bunch of ways you can use that info to control an image meter. One way is to add an action to the Calc measure.

[CalcTranslatePIDToRunningState]
Measure=Calc
Formula=MeasureProcessPID > 0 ? 1 : 0
IfAboveValue=0
IfAboveAction=!RainmeterSetVariable OfficeImage "#CURRENTPATH#imageYES.png"
IfBelowValue=1
IfBelowAction=!RainmeterSetVariable OfficeImage "#CURRENTPATH#imageNO.png"

Then be sure you have a variable initialized in [Variables]
OfficeImage=""

And on the image meter:

[ImageMeter]
Meter=Image
ImageName=#OfficeImage#
DynamicVariables=1

This is just an example. The important thing are the two measures at the top which identify if the app is currently running or not. How you meld that information into your image with the hover effects and such is up to you.
User avatar
Nebbishatudub
Posts: 26
Joined: January 28th, 2011, 4:57 am
Location: Washington, DC

Re: Change image when program closes

Post by Nebbishatudub »

Here's another example of what you can do. One note, I'm not sure what is faster, using the "Substitute" method that I use or the "Above/Below" method described by jsmorley; but this is how I've done it for my application launcher.

Since I have a bunch of different applications which I use this for (a string of 15), I've created an "Application Button Style" which helps to auto-arrange the icons. You need to add "X=whatever" to the first button you create if you use this.
[ButtonStyle]
X=27r
Y=(#SCREENAREAHEIGHT#-28)
W=27
H=27
DynamicVariables=1
Once you've made this style there are 3 [Sections] that you'll need for each application you want to watch/launch:
> Running?
> Icon
> Button

Here is an example using Photoshop. It is the fourth button on my chain, and there is also a displayed name section (which I'll include at the end) that activates on mouseover.

Code: Select all

[MeasureAdobePhotoshop]
Measure=Plugin
Plugin=ResMon.dll
ResCountType=USER
ProcessName=Photoshop.exe

[AdobePhotoshopIcon]
Measure=CALC
Formula=(MeasureAdobePhotoshop) ? 1 : 0
Substitute="1":"RUNNING Image Path","0":"NOT RUNNING Image Path"

[Button4]
Meter=IMAGE
MeterStyle=ButtonStyle
ImageName=[AdobePhotoshopIcon]
MouseOverAction=!execute [!RainmeterSetVariable AppName "- Photoshop -"][!RainmeterUpdateMeter DisplayAppName][!RainmeterRedraw]
MouseLeaveAction=!execute [!RainmeterSetVariable AppName " "][!RainmeterUpdateMeter DisplayAppName][!RainmeterRedraw]
LeftMouseDownAction=!Execute ["C:\Program Files (x86)\Adobe\Adobe Photoshop CS3\Photoshop.exe"][!RainmeterRedraw]
Here is the code for displaying the application name. Note, you'll need to create a variable "AppName" earlier up in the skin. You can delete the "MouseOverAction" and "MouseLeaveAction" lines from the previous section if you do not want to show the application name (or whatever you specify) when you mouseover the button.
[DisplayAppName]
Meter=STRING
MeterStyle=StyleText
FontColor=255, 255, 255, 100
StringStyle=BOLD
StringEffect=BORDER
FontEffectColor=128, 192, 255, 60
Text=#AppName#
X=343
Y=(#SCREENAREAHEIGHT#-48)
DynamicVariables=1
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Change image when program closes

Post by jsmorley »

My way is clearly better. If you use Nebbishatudub's code, the terrorists win...

:-)
User avatar
Nebbishatudub
Posts: 26
Joined: January 28th, 2011, 4:57 am
Location: Washington, DC

Re: Change image when program closes

Post by Nebbishatudub »

but I... and they... <shifty eyes> :confused: