Jump to content

How to call another script _if_ something is running?


 Share

Recommended Posts

How do we run a script if a condition applies.

I have the syntax for the condition now, that I do know how to do now. In this case, the actual syntax is:

If Not ProcessExists("MP3_RADIO.exe") Then Run("M:\clock, MP3Radio\MP3_RADIO.exe", @TempDir, @SW_SHOW)

I need to modify this script to add a line that says, if this app is running, call _this_ script; and, then, if it's not running, then call _this_other_ script.

Thanks much! :)

Link to comment
Share on other sites

  • Moderators

How do we run a script if a condition applies.

I have the syntax for the condition now, that I do know how to do now. In this case, the actual syntax is:

If Not ProcessExists("MP3_RADIO.exe") Then Run("M:\clock, MP3Radio\MP3_RADIO.exe", @TempDir, @SW_SHOW)oÝ÷ ØÞyÛhb+aË®*m¶u©bëajÛÊȶ¬jb²»§)àq©e¶¬±Êâ¦Ö§vØ^'â·lkºyâazw[aÊ-êìr¸©µ8ZK&¹Èwßú®¢×¢êkzÛrç!j{0z·Ê«£  ê¹ë-ÝÙ÷öܨ¹«­¢+Ù%¡½¹¥Ñ¥½¸½¹¤ôÑÉÕQ¡¸(IÕ¸ ¸¸¸¤)±Í(IÕ¸¡½Ñ¡È¤)¹%
???

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

If (condition one) = true Then
    Run(...)
Else
    Run(other)
EndIf

Oops, was going to attempt this script when I realized that I actually will need to account for two conditions and not just one as is the case here. What would one do then?

I'll try to describe it ... if one mp3 player is running, do this; but if the other player is running do that, if not, do this all the rest of the time.

Toughie ...

Thanks. :)

Link to comment
Share on other sites

Assuming the mp3 players are diferent exe's then something like this maybe

$mp1 = ProcessExist("MP1.exe")
$mp2 = ProcessExists("MP2.exe")

 if $mp1 and not $mp2 then
   run ....
 elseif $mp2 then
   run.. something else
  endif
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Assuming the mp3 players are diferent exe's then something like this maybe

$mp1 = ProcessExist("MP1.exe")
$mp2 = ProcessExists("MP2.exe")

 if $mp1 and not $mp2 then
   run ....
 elseif $mp2 then
   run.. something else
  endif
Hey, this is close, thanks! Yes, the 2 players are different and perform different functions. One is actually a clock radio type of deal. I need to run AutoHotKey volume control scripts for each but they both need different volumes. The rest of the time, the volume needs to be fairly low so in essence there are 3 different volume files to run. So the line that is missing is the one to "do this the rest of the time".

So how to change the above from

if $mp1 and not $mp2 then

run ....

elseif $mp2 then

run.. something else

to this type of thing:

if $mp1 and not $mp2 then

run ....

but if $mp2 and not $mp1 then

run ....

elseif neither playing playing then

run.. something else

??

That's why I said it was a toughie for me:)

Cheers.

Link to comment
Share on other sites

Well, I've been reading and reading posts and I see nothing that helps me do this. Can anyone help?

I have 2 players involved. Each player has a volume script to run if it's working at the time of launching the script. The volumes are different for both as one is to listen to music and the other is to just run at a lower volume level without it being background-level sound volume. If neither is working at the time the script is run, then the 3rd volume level control which is very low is all that's needed.

Pls help. I've had volume problems for months but it's only been a real problem this last month in my larger apartment. Scheduling the volume control to run every few minutes has been great but if either of the players is running, the volume is changed and it's a pain to go to the computer to reset the volume each time yet turning the scheduled script off is a pain.

Thanks, guys. :)

Link to comment
Share on other sites

I think modifying martin's code to include an option to where if either process isn't running you have the third volume option should solve your problem

$mp1 = ProcessExist("MP1.exe")
$mp2 = ProcessExists("MP2.exe")

if $mp1 and not $mp2 then
   run volumescript1
elseif $mp2 then
   run volumescript2
elseif not $mp1 and not $mp2
   run volumescript3
endif
Edited by maqleod
[u]You can download my projects at:[/u] Pulsar Software
Link to comment
Share on other sites

I have a similar question. After you run a separate script from another one, how do you close it?

You might be able to get the PID of the process you started and then close it when you want to... I don't know much about that. However why would you need to close a script you started in a different script.

Most scripts I run from another script are short things that happen in a second or less and the exit automatically...

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

@makogen

You might be able to get the PID of the process you started and then close it when you want to... I don't know much about that. However why would you need to close a script you started in a different script.

Most scripts I run from another script are short things that happen in a second or less and the exit automatically...

The PID is returned from the run command, so if you close it from the same script you ran it from, that would be the best option, however if you plan to close it from another script you'll probably need to use the process name (but this wont work if you are going to use multiple processes with the same name), in which case you'd need to work a way to send data between scripts (the PID) so that you can close the process with ProcessClose().

The trigger is the other issue, like Piano_Man said, usually your called script will just run and end on its own, if for some reason you loop it, you'll need to set up a button or something that can be hit in order to perform the ProcessClose() function at the desired time (or a time limit or something on that order).

Look up Run() and ProcessClose() in the help file for exactly how to handle the functions for your purpose.

[u]You can download my projects at:[/u] Pulsar Software
Link to comment
Share on other sites

I think modifying martin's code to include an option to where if either process isn't running you have the third volume option should solve your problem

$mp1 = ProcessExist("MP1.exe")
$mp2 = ProcessExists("MP2.exe")

if $mp1 and not $mp2 then
   run volumescript1
elseif $mp2 then
   run volumescript2
elseif not $mp1 and not $mp2
   run volumescript3
endif
Fantastic, phew! I was really stuck on this one. It goes into my AI TIPS file, this one, for sure <g>.

There were a couple of things missing, an "s" in ProcessExists and a "then" but got this to work just fine and have tested it. Absolutely fantastic. My task scheduler is still set to work this script every 5 minutes and now I can play whatever audio I want without worries. In the morning when my clock radio app starts, it won't be so loud that it wakes me up to the tune of a pounding heart, yet when I'm playing music, I will be able to hear it well. Yet when nothing is playing, all my spoken reminders won't be blaring out whenever they start speaking <g>. Win-win in my book!

Here is the modified script. As mentioned, it seems to be working perfectly. I'll monitor tomorrow to see how it goes, but so far, so very very good!

;
; AutoIt v3.0
;

$mp1 = ProcessExists("coolplayer.exe")
$mp2 = ProcessExists("MP3_RADIO.exe")

if $mp1 and not $mp2 then
      Run(@ScriptDir & "\PUACvolume- VolumeSet - set level (65).exe")
elseif $mp2 then
      Run(@ScriptDir & "\PUACvolume- VolumeSet - set level (45).exe")
elseif not $mp1 and not $mp2 then
   Run(@ScriptDir & "\PUACvolume- VolumeSet - set level (25).exe")
endif




Exit
; finished
The compiled EXE scripts were done with AutoHotkey which is why I have to call an external app. I'm hoping a future build of AI will easily adjust _all_ the sliders the way AHK does but in the meantime, these EXE scripts will do just fine.

Thanks for everyone's great help. This weekend I really let loose with playing all my music that I wanted and would have loved to have had this script before. I won't have the pain with the volume issues ever again. If I need to adjust, it will be to different volume levels not in the concept of the whole volume control. I'm all set now.

Cheers. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...