Sign in to follow this  
Followers 0
Diana (Cda)

Run only if two conditions are met?

15 posts in this topic

Some time back I recvd great help where WinExists was brought to my attention as a way to have the script not t proceed if it finds a particular file open.

However, I've never managed to get the syntax right for more than one condition though I've read the help file and scanned the forum several times since then. Can't get it to work yet. My latest attempt today is this:

If NOT WinExists(@ScriptDir & "\PUAC- LaunchIfNotRunning - DO NOT RUN APPS.txt") = True AND If Not ProcessExists("SayTime95.exe") = True THEN Run($ThisPartition & "\CLOCK\clockSpeech, SayTime 95 v4.05\APP- SayTime 95 v4.05\SayTime95.exe","", @SW_HIDE)

What is needed is:

- if the text file "PUAC- LaunchIfNotRunning - DO NOT RUN APPS.txt" is not open,

- AND

- "SayTime95.exe" is not running

- THEN

- LAUNCH "SayTime95.exe".

But the error keeps coming back that the "If" requires a "Then". So I've obviously goofed somewhere.

Share this post


Link to post
Share on other sites



You simply have to remove the second "If":

If NOT WinExists(@ScriptDir & "\PUAC- LaunchIfNotRunning - DO NOT RUN APPS.txt") = True AND If Not ProcessExists("SayTime95.exe") = True THEN Run($ThisPartition & "\CLOCK\clockSpeech, SayTime 95 v4.05\APP- SayTime 95 v4.05\SayTime95.exe","", @SW_HIDE)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

You simply have to remove the second "If":

If NOT WinExists(@ScriptDir & "\PUAC- LaunchIfNotRunning - DO NOT RUN APPS.txt") = True AND If Not ProcessExists("SayTime95.exe") = True THEN Run($ThisPartition & "\CLOCK\clockSpeech, SayTime 95 v4.05\APP- SayTime 95 v4.05\SayTime95.exe","", @SW_HIDE)

Well, d'uh! That's what's been holding me up all this time ... <g> Too funny. Tested it and works great. I simplified things by replacing everything with variables. Has made life easier.

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$Condition1 = NOT WinExists(@ScriptDir & "\PUAC- LaunchIfNotRunning - DO NOT RUN APPS.txt")     ; text file is not open to disable condition
$Condition2 = NOT ProcessExists("SayTime95.exe")     ; SayTime is not running condition
$Condition3 = Not ProcessExists("wv_player.exe")     ; WavPlay is not running condition
$Condition4 = Not ProcessExists("CoolPlayer.exe")    ; CoolPlayer is not running condition
;------------------------------------------------
$ThisPartition = StringLeft(@ScriptDir, 2)
$Process2Run1 = $ThisPartition & "\CLOCK\clockSpeech, SayTime 95 v4.05\APP- SayTime 95 v4.05\SayTime95.exe"
$Process2Run2 = @ScriptDir & "\0- PAYDAY wakeup music 01 (3 songs).wav"
$Process2Run3 = @ScriptDir & "\Harry Potter music.m3u"
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


If $Condition1 = True AND $Condition2 = True THEN Run($Process2Run1)     ; run SayTime if conditions met
Sleep(1500)
If $Condition1 = True and $Condition4 = True Then ShellExecute($Process2Run3)     ; run m3u if conditions met

Thanks! :P

Share this post


Link to post
Share on other sites

You simply have to remove the second "If":

If NOT WinExists(@ScriptDir & "\PUAC- LaunchIfNotRunning - DO NOT RUN APPS.txt") = True AND If Not ProcessExists("SayTime95.exe") = True THEN Run($ThisPartition & "\CLOCK\clockSpeech, SayTime 95 v4.05\APP- SayTime 95 v4.05\SayTime95.exe","", @SW_HIDE)

Well, d'uh! That's what's been holding me up all this time ... <g> Too funny. Tested it and works great. I simplified things by replacing everything with variables. Has made life easier.

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$Condition1 = NOT WinExists(@ScriptDir & "\PUAC- LaunchIfNotRunning - DO NOT RUN APPS.txt")     ; text file is not open to disable condition
$Condition2 = NOT ProcessExists("SayTime95.exe")     ; SayTime is not running condition
$Condition3 = Not ProcessExists("wv_player.exe")     ; WavPlay is not running condition
$Condition4 = Not ProcessExists("CoolPlayer.exe")    ; CoolPlayer is not running condition
;------------------------------------------------
$ThisPartition = StringLeft(@ScriptDir, 2)
$Process2Run1 = $ThisPartition & "\CLOCK\clockSpeech, SayTime 95 v4.05\APP- SayTime 95 v4.05\SayTime95.exe"
$Process2Run2 = @ScriptDir & "\0- PAYDAY wakeup music 01 (3 songs).wav"
$Process2Run3 = @ScriptDir & "\Harry Potter music.m3u"
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


If $Condition1 = True AND $Condition2 = True THEN Run($Process2Run1)     ; run SayTime if conditions met
Sleep(1500)
If $Condition1 = True and $Condition4 = True Then ShellExecute($Process2Run3)     ; run m3u if conditions met

Thanks! :P

Share this post


Link to post
Share on other sites

You simply have to remove the second "If":

If NOT WinExists(@ScriptDir & "\PUAC- LaunchIfNotRunning - DO NOT RUN APPS.txt") = True AND If Not ProcessExists("SayTime95.exe") = True THEN Run($ThisPartition & "\CLOCK\clockSpeech, SayTime 95 v4.05\APP- SayTime 95 v4.05\SayTime95.exe","", @SW_HIDE)

Thank you, that works perfectly!

This is what I did with that, besides making everything into variables to make the syntax easier to deal with:

If $Condition1 = True AND $Condition2 = True THEN Run($Process2Run1)     ; run SayTime if conditions met
Sleep(1500)
If $Condition1 = True and $Condition4 = True THEN ShellExecute($Process2Run3)

Thanks! :P

Share this post


Link to post
Share on other sites

Is there a way, though, to run two THEN's, meaning, what if there is something like this:

If $Condition1 = True AND $Condition2 = True THEN Run($Process2Run1) AND Run($Process2Run2)

The above doesn't work but is there a way to have 2 things happen if one or more conditions met?

Thanks. :P

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Is there a way, though, to run two THEN's, meaning, what if there is something like this:

If $Condition1 = True AND $Condition2 = True THEN Run($Process2Run1) AND Run($Process2Run2)

The above doesn't work but is there a way to have 2 things happen if one or more conditions met?

Thanks. :P

If $Condition1 = True AND $Condition2 = True THEN
    Run($Process2Run1) 
    Run($Process2Run2)
   ;anythiong else to be done if condition is true
Else
 ;anything to be done if condition is not true
EndIf
[code=auto:0]

But isn't this clear from the help?


            
                


    Edited  by martin
    
    

            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
            




  
  
    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.
  


        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
SmOke_N   

    
        
    
             193
    
        
    

        
            
                It's not what you know ... It's what you can prove!
            
            

            
                

    
        
    

            
            Moderators
            
                
            
            
                

    
        
    
             193
    
        
    

                16,134 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #8 · 
            Posted 
            
            
            
        
    

    


            
        
            I'm curious if this would work:If $Condition1 AND $Condition2 THEN Run($Process2Run1) + Run($Process2Run2)
Can't see why not really.


[center]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.[/center]

Share this post


Link to post
Share on other sites

I'm curious if this would work:
If $Condition1 AND $Condition2 THEN Run($Process2Run1) + Run($Process2Run2)oÝ÷ Ø&§ßÛlyì!Êz-­æ¥/êº^"ÛÊËaÇ(uà.¶-ºè¬¸§{xÐX¥{~7ãyðôß ¨Ø­÷
Just curious.

Thanks. Cheers. :P

Share this post


Link to post
Share on other sites

I'm curious if this would work:

If $Condition1 AND $Condition2 THEN Run($Process2Run1) + Run($Process2Run2)
Can't see why not really.
Seems like a good idea but doesn't work. :P

Maybe the nearest is to have

If $Condition1 And $Condition2 then runBoth()

Func RunBoth()
  Run($a)
  Run($b)
EndFunc

But you could have something like

If $cond1 And $Cond2 then Consolewrite(Run("cmd.exe") And Run("cmd.exe"))

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.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

But you could have something like

If $cond1 And $Cond2 then Consolewrite(Run("cmd.exe") And Run("cmd.exe"))
Why Consolewrite() and not Call()? Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Seems like a good idea but doesn't work. :P

Maybe the nearest is to have

If $Condition1 And $Condition2 then runBoth()

Func RunBoth()
  Run($a)
  Run($b)
EndFunc

But you could have something like

If $cond1 And $Cond2 then Consolewrite(Run("cmd.exe") And Run("cmd.exe"))
This is not really good of us to show this stuff lol... but this does work:
Local $codition1 = 1, $condition2 = 1, $i_ret
If $codition1 And $condition2 Then $i_ret = Run("cmd.exe") & Run("cmd.exe")
ConsoleWrite($i_ret & @CRLF)oÝ÷ ØGb´    ݶ¬jëh×6Local $codition1 = 1, $condition2 = 1, $i_ret
If $codition1 And $condition2 Then $i_ret = Run("cmd.exe") + Run("cmd.exe")
ConsoleWrite($i_ret & @CRLF)
Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

Seems like a good idea but doesn't work. :(

Maybe the nearest is to have

If $Condition1 And $Condition2 then runBoth()

Func RunBoth()
  Run($a)
  Run($b)
EndFunc

But you could have something like

If $cond1 And $Cond2 then Consolewrite(Run("cmd.exe") And Run("cmd.exe"))
Actually, I see now that I gave a bad example. I happened to give the one script that uses run (my bad). The majority use ShellExecute. Bad, bad ... <g>

It's a shame that nothing seems to work where everything is easily on one line like the example that doesn't work above. It would be tricky getting everything to work otherwise. The above workaround still uses 5 lines instead of 1 so my 3-line script above would translate into 15 lines. Yuck. <sigh> It's just that I foresee having another script that will use even 4 lines instead of my 3 here and it all would be just such a mess. I'll guess I'll have to live without the extra sleep and beeps that would make the script easier, that's what I needed to add. But adding all these extra lines would make "maintenance" and editing of such a script a nightmare esp. since I've been living without these extra sleepand beep "aids". I had them before I changed to the 2 conditions approach as shown here.

But thanks, everyone. I learn a lot every time I fine-tune a script to do more precisely what is needed. This 2 condition approach all on 1 script line allows me a much more efficient way to "disable" some scripts. I just will continue to not have the extras until I figure out an easy way to add them that doesn't add any more lines.

Thanks! :P

Share this post


Link to post
Share on other sites

You are bug manipulators


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I wrote a little test script:

Opt("WinTitleMatchMode",2)
          If NOT WinExists("LaunchIfNotRunning") AND NOT ProcessExists("SayTime95.exe") Then
               Run("PourMyCoffeeToo.exe")
               ProcessWait("PourMyCoffeeToo.exe")
              If Not ProcessExists("CoolPlayer.exe") Then ShellExecute("All That Remains - This Calling.mp3")
          EndIfoÝ÷ Ùj+çeGr«Ê¢¼¨¹«­¢+Ù=ÁÐ ÅÕ½Ðí]¥¹Q¥Ñ±5Ñ¡5½ÅÕ½Ðì°È¤(%9=P]¥¹á¥ÍÑÌ ÅÕ½Ðí1Õ¹¡%9½ÑIÕ¹¹¥¹ÅÕ½Ðì¤99=PAɽÍÍá¥ÍÑÌ ÅÕ½ÐíMåQ¥µäÔ¹áÅÕ½Ðì¤Q¡¸(IÕ¸ ÅÕ½ÐíÉ¥ÙèÀäÈí
1=
,ÀäÈí±½­MÁ °MåQ¥µäÔØиÀÔÀäÈíA@´MåQ¥µäÔØиÀÔÀäÈíMåQ¥µäÔ¹áÅÕ½Ðì¤(AɽÍÍ]¥Ð ÅÕ½ÐíMåQ¥µ¹áÅÕ½Ðì¤(%9½ÐAɽÍÍá¥ÍÑÌ ÅÕ½Ðí
½½±A±åȹáÅÕ½Ðì¤Q¡¸M¡±±áÕÑ ÅÕ½Ðí!ÉÉäA½ÑÑȵÕÍ¥¹´ÍÔÅÕ½Ðì¤(¹%oÝ÷ ØÚ0ü¨»§¶Ú,µªíºÈ§ö«¦åzËhr§ëayø¥y·¢
ek'¶§#
.Û.¬¶Øb±«­¢+Ù=ÁÐ ÅÕ½Ðí]¥¹Q¥Ñ±5Ñ¡5½ÅÕ½Ðì°È¤(ÀÌØíôÅÕ½ÐìÀ´AedÝ­ÕÀµÕÍ¥ÀÄ Ìͽ¹Ì¤¹ÝØÅÕ½Ðì(ÀÌØíôÅÕ½Ðí!ÉÉäA½ÑÑȵÕÍ¥¹´ÍÔÅÕ½Ðì(ÀÌØíôÅÕ½Ðí±°Q¡ÐIµ¥¹Ì´Q¡¥Ì
±±¥¹¹µÀÌÅÕ½Ðì(%9=P]¥¹á¥ÍÑÌ ÅÕ½Ðí1Õ¹¡%9½ÑIÕ¹¹¥¹ÅÕ½Ðì¤99=PAɽÍÍá¥ÍÑÌ ÅÕ½ÐíMåQ¥µäÔ¹áÅÕ½Ðì¤Q¡¸(IÕ¸ ÅÕ½ÐíÉ¥ÙèÀäÈí
1=
,ÀäÈí±½­MÁ °MåQ¥µäÔØиÀÔÀäÈíA@´MåQ¥µäÔØиÀÔÀäÈíMåQ¥µäÔ¹áÅÕ½Ðì¤(AɽÍÍ]¥Ð ÅÕ½ÐíMåQ¥µ¹áÅÕ½Ðì¤(%9½ÐAɽÍÍá¥ÍÑÌ ÅÕ½Ðí
½½±A±åȹáÅÕ½Ðì¤Q¡¸M¡±±áÕÑ ÀÌØí¤íIÁ±Ý¥Ñ ÀÌØí½ÈÑÑȵÕÍ¥©Ý¥¹¬¨(¹%

There's a lot of possible...heh...overkill in your script, like if saytime automatically closes itself after running, you could use runwait and do away with processwait...or if the file will still open w/ coolplayer running, you can simply add the shellexecute command to the list of things to do in the ifthen...only you can decide what to do with your script but those are some ideas.

Edited by Overkill

Share this post


Link to post
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
Sign in to follow this  
Followers 0