Author Topic: Help with how to use {PROCESSEXISTS:} token properly  (Read 1784 times)

jyashi

  • Guest
Help with how to use {PROCESSEXISTS:} token properly
« on: October 23, 2018, 03:17:30 AM »
I have had it with playing games for hours on end and not getting work done. In my attempt to discipline myself i am using voice attack to automate some discipline (which i clearly lack).

I want to use the {PROCESSEXISTS:~~Steam} token to.... you guessed it... check if steam is running or not and if it is to use that 0 or 1 value in a command to kill steam (and play a Text To Speech lecturing myself about my actions).

But whenever i use {PROCESSEXISTS:~~Steam} in the begin if conditional variable name section i get error message
" Variable names may not contain colons".

So how do i use VA to check if Steam is running in the background which i can combine with an if else statement?

Thank you, and watch out for my name in Forbes Rich list in 48 years time.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Help with how to use {PROCESSEXISTS:} token properly
« Reply #1 on: October 23, 2018, 03:46:19 AM »
Only the "Text" tab of the "Begin a Conditional (If Statement) Block" action supports tokens(As indicated by the "Variable Name / Token" caption).

Tokens are not variables, so if a field expecting a variable doesn't explicitly support tokens it'll process the token as if it's the name of a variable(which don't allow colons).

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Help with how to use {PROCESSEXISTS:} token properly
« Reply #2 on: October 23, 2018, 01:00:41 PM »
Echoing what Pfeil is talking about, {PROCESSEXISTS:} cannot accept explicit text (like "~~Steam" in your example). This token takes a text variable as input. So you must first define a text variable with a value of "~~Steam" and then you can insert that text variable as {PROCESSEXISTS:YourTextVariable} for evaluation.

The below example allows you to specify the process (EXE) name (here I'm using the calculator) and "business time" range of interest, and the command will check these against existing processes and the current time.

Code: [Select]
// Define process of interest in text variable
Set Text [~~MyProcess] to 'calculator'

// Define range of times of interest. Only the time matters here.
Set date [~~BusinessTimeStart] value to 10/23/2018 5:00:00 PM
Set date [~~BusinessTimeEnd] value to 10/23/2018 10:30:00 PM

// Check if current time is within time range of interest
Begin Condition : ([{EXP: IIF({TIMEHOUR24}+{TIMEMINUTE}/60>={TIMEHOUR24:~~BusinessTimeStart}+{TIMEMINUTE:~~BusinessTimeStart}/60, 1, 0)}] Equals '1' AND [{EXP: IIF({TIMEHOUR24}+{TIMEMINUTE}/60<={TIMEHOUR24:~~BusinessTimeEnd}+{TIMEMINUTE:~~BusinessTimeEnd}/60, 1, 0)}] Equals '1')
    // Check if process of interest is running
    Begin Text Compare : [{PROCESSEXISTS:~~MyProcess}] Equals '1'
        // Lecture accordingly
        Write [Blue] ''{TXT:~~MyProcess}' is running during business time' to log
        Write [Blue] 'Naughty naughty Kool-Aid' to log
    End Condition
Else
    // Game on!
    Write [Blue] 'Outside business hours. Have fun!' to log
End Condition

Note that the command only looks at the time portion of the date-time variables when evaluating whether you're within the "business time" window. You can insert the conditional statement block into a loop to keep evaluating the statements, though you'll want to also add a pause (maybe 5 or 15 minutes?) at the very end of the conditional block (but still within the loop) so you don't loop constantly. Depending on your needs you may also want to include a way to break out of the loop.

I haven't made a lot of commands involving date-time variables, and there may be more efficient ways of evaluating if the current time is within "business time."

HTH  :)