RunCommand

Share your custom plugins and applications to enhance Rainmeter.
User avatar

RunCommand

October 12th, 2013, 8:50 am
Brian
Developer   [1486 posts]

RunCommand Plugin:

Note: As of the Rainmeter 3.3 r2493 beta of December 27, 2015, RunCommand is included in the Rainmeter distribution, and there is no need to download, install, or include RunCommand within an .rmskin. RunCommand just comes with Rainmeter.

This is a simple little plugin to run a program with an initial state (ie. Hidden, Minimized, Maximized) and to also retrieve the output (or stdout) of the program (especially command-line programs).

Options include:

  • Program - The program to run. The default value is the %ComSpec% environment variable (ie. cmd.exe) with the parameters "\U" for Unicode pipe output and "\C" to close the program when finished.
  • Parameter - Command-line parameters (if any). If no "Program" is given, this option represents the "command" you would run from the command-line.
  • State - Initial "state" of the program. Options include: Hide (default), Show, Minimized, or Maximized. Some programs (like Calc.exe) explicitly show themselves no matter what the OS initially tells them they should be, so not all programs will respond to this option.
  • FinishAction - Action to run after the program has exited.
  • OutputFile - File where the output is saved. The file's encoding will correlate to the OutputType option. Use this if you want the output saved to a file.
  • OutputType - Type of output to be expected. Options include: Ansi, Utf8, or Utf16 (default).
  • StartInFolder - Starts the program in this folder.
  • Timeout - In milliseconds. The program is will close after this interval. -1 is the default value.

Commands:

  • Run - Runs the program. Example: !CommandMeasure MeasureName Run
  • Close - Attempts to close the program. The program may prompt the user to close. Example: !CommandMeasure MeasureName Close
  • Kill - Terminates the program without notice. Recommended for programs started in the hidden state State=Hide. Example: !CommandMeasure MeasureName Kill

Note: Because Rainmeter strips any quotes from the start and end of an option (if both exist), it is important to double quote the Program and Parameter options if needed (ie. Program=""C:\Program Files\Some Program\Something with a space.exe"")


For examples, changes and additions, check the official Rainmeter documention here: https://docs.rainmeter.net/manual-beta/plugins/runcommand/

-Brian
User avatar

Re: RunCommand - WIP

October 12th, 2013, 12:24 pm
moshi
   [1851 posts]

cool, that will make a few things easier. looking forward to play with it.

i just hope people use their brain should they share skins using it. particularly the use together the NowPlaying plugin can cause trouble. while starting an application hidden works flawlessly with WMP on Windows 7, iTunes for example is problematic. means: once you have iTunes started hidden, you wont be able to open an iTunes window until you close it from the task manager.

i hope you get the Unicode issue solved. it is the same problem with redirects from the command line. my favorite solution would still be that Rainmeter would have some native html de/encoding capability. (which would be cool for any web api use as well)
User avatar

Re: RunCommand - WIP

October 12th, 2013, 12:33 pm
jsmorley
Developer   [16029 posts]

Starting apps in a "hidden" state is a business with some inherent risks in any case. The obvious answer is to have an OnCloseAction in the skin that closes or kills the app in question, but in the rare case that Rainmeter crashes, you can be left with an invisible process that can be problematic for many users.

I would be tempted to have both an OnRefreshAction and OnCloseAction that closes / kills the app, then use this plugin to start it when appropriate in the context of the skin functionality.

That way, even in the worst case, simply refreshing the skin or restarting Rainmeter should set things right.
User avatar

Re: RunCommand - WIP

October 12th, 2013, 1:04 pm
fonpaolo
Moderator   [1111 posts]

I'm looking at it with great interest... :D
User avatar

Re: RunCommand - WIP

October 13th, 2013, 9:23 pm
moshi
   [1851 posts]

Brian wrote:It should also be noted that this plugin does not retrieve Unicode from the output of command-line programs. I am investigating ways to detect the encoding of output of a program, but it seems there is problems when piping the output of one program into another program and losing any BOM associated with the output (if any existed). So as of right now, all output is assumed to be ANSI encoded.


just downloaded it. i noticed that what the plugin does is actually worse than the > redirect.

the skin itself displays the output just like > redirect.

but the saved output file just "stops" when there is a character it does not like.

attached screenshot, due to bad English:


(it should be Datenträger btw.)
User avatar

Re: RunCommand - WIP

October 13th, 2013, 10:32 pm
Brian
Developer   [1486 posts]

moshi wrote:just downloaded it. i noticed that what the plugin does is actually worse than the > redirect.

the skin itself displays the output just like > redirect.

but the saved output file just "stops" when there is a character it does not like.

attached screenshot, due to bad English:


This is an easy fix, but I have not implemented it yet because I am still mulling over a decision on whether or not to require a specified encoding for output. For example, a new option called OutputEncoding...with values like ANSI, UTF8, or UTF16. Or, I could force the output file encoding to be UTF16, which should cover all bases.

-Brian
User avatar

Re: RunCommand - WIP

October 14th, 2013, 9:56 am
moshi
   [1851 posts]

i know i am probably asking for too much, but what would be really cool would be if the plugin could measure this:



it's an application that plays playlists from the internet and as you can see also the current track's Icecast meta data. i have not been successful getting this metadata for Rainmeter with other methods though.
User avatar

Re: RunCommand - WIP

October 14th, 2013, 11:14 am
moshi
   [1851 posts]

this code:

Code: Select all

[Command_1]
Measure=Plugin
Plugin=RunCommand
Parameter=dir
FinishAction=[!SetOption Output Text "[Command_1]"][!UpdateMeter Output][!Redraw]
DynamicVariables=1

[Output]
Text="waiting"
Meter=STRING
X=0
Y=0
FontColor=ffffff
FontSize=10
FontFace=Segoe UI
StringAlign=Left
AntiAlias=1
DynamicVariables=1
SolidColor=00000050
Padding=10,10,10,10


doesn't work for me. it sets the option to nothing "^$"
User avatar

Re: RunCommand - WIP

October 14th, 2013, 11:21 am
moshi
   [1851 posts]

moshi wrote:this code:
...
doesn't work for me. it sets the option to nothing "^$"


ok, i can get this working with OnChangeAction instead of FinishAction
User avatar

Re: RunCommand - WIP

October 14th, 2013, 3:58 pm
Brian
Developer   [1486 posts]

moshi wrote:this code:

Code: Select all

[Command_1]
Measure=Plugin
Plugin=RunCommand
Parameter=dir
FinishAction=[!SetOption Output Text "[Command_1]"][!UpdateMeter Output][!Redraw]
DynamicVariables=1

[Output]
Text="waiting"
Meter=STRING
X=0
Y=0
FontColor=ffffff
FontSize=10
FontFace=Segoe UI
StringAlign=Left
AntiAlias=1
DynamicVariables=1
SolidColor=00000050
Padding=10,10,10,10


doesn't work for me. it sets the option to nothing "^$"


This doesn't work because FinishAction is being executed before Rainmeter has asked the plugin for its string value. To make this work properly, you should add escape's to the measure you are setting.
FinishAction=[!SetOption Output Text "[*Command_1*]"]

Actually this way is highly inefficient anyway. It is often forgotten that when DynamicVariables is defined, the meter/measure will read all of its values on every update. In some instances, this behavior cannot be avoided to get the current value of the measure - but avoiding DynamicVariables when you can makes your skin that much more efficient without processing all the code for values that have not changed. For this particular example, just setting the "MeasureName" of the meter is the best way to go to avoid all the unnecessary processing in this case.
[!SetOption Output MeasureName Command_1][!UpdateMeter Output][!Redraw]

@mgp123.exe: I am not entirely sure how that programs works. If the program expects input (even to close), then it won't play well with this plugin at all. I noticed you did a control-C to exit that program, so I am not sure if it will work or not. I can try to play with that program later.


Update: I have made some progress with Unicode for the plugin, however, it has introduced some other problems that I am still working out. Hopefully a solution presents itself.

-Brian

Return to “Plugins & Addons”



Who is online

Users browsing this forum: No registered users and 2 guests