mentosan Posted February 3, 2009 Share Posted February 3, 2009 (edited) Hello friends ! I'm having a script with plenty of conditionally run statements. I want to add to the default tray menu icon, besides Pause and Exit option, the Start button. For this I'm using: Opt("TrayMenuMode",0);append item to the existing traymenu To display the new item I'm using this line: $traymenuitem = TrayCreateItem ("Start") So far so good.The problem,for me, begins here.I want this button to bring it alive.Actually I want when the Start option is clicked, script should resume running from beginning.I don't know where in the script to insert the loop with TrayGetMsg() (checked from the au3 help file). The script has this pattern: -declaration of variables -TrayCreateItem() -HotKeySet -For $n=0 to.... -If ProcessExists Then ....Else Call ("FunctionX") -Sleep (.....);Sleep 25 minutes -FunctionX() ..EndFunc Thank you! Edited February 4, 2009 by mentosan Link to comment Share on other sites More sharing options...
mentosan Posted February 4, 2009 Author Share Posted February 4, 2009 Any help ? Link to comment Share on other sites More sharing options...
Varian Posted February 4, 2009 Share Posted February 4, 2009 Maybe like this: Create a "frontend" script that has your TrayMenu item (with "Start"); When "Start" is selected, the function "StartMainScript" function calls your other script. Opt('TrayMenuMode', 1) Opt('TrayOnEventMode', 1) $Traymenuitem = TrayCreateItem('Start') TrayItemSetOnEvent(-1, 'StartMainScript') While 1 Sleep(50) WEnd Func StartMainScript() Run('MainScript.exe') ProcessWaitClose('MainScript.exe') EndFunc Link to comment Share on other sites More sharing options...
mentosan Posted February 4, 2009 Author Share Posted February 4, 2009 Good ideea. Didn't think about this, to split into 2 scripts. I'll give it a try. Thx Link to comment Share on other sites More sharing options...
mentosan Posted February 4, 2009 Author Share Posted February 4, 2009 I did test what you have suggested, with a frontend script, but now I only Have Start button. No Pause and Exit anymore. Link to comment Share on other sites More sharing options...
Varian Posted February 4, 2009 Share Posted February 4, 2009 (edited) Sorry 'bout that. Change to: Opt('TrayMenuMode', 0) Opt('TrayOnEventMode', 1) Opt('TrayAutoPause', 0) ;stops script from pausing automatically when you click the tray icon $Traymenuitem = TrayCreateItem('Start') TrayItemSetOnEvent(-1, 'StartMainScript') While 1 Sleep(50) WEnd Func StartMainScript() Run('MainScript.exe') ProcessWaitClose('MainScript.exe') EndFunc Edited February 4, 2009 by Varian Link to comment Share on other sites More sharing options...
mentosan Posted February 4, 2009 Author Share Posted February 4, 2009 It is not working. My script is not started. Link to comment Share on other sites More sharing options...
Varian Posted February 4, 2009 Share Posted February 4, 2009 If this script is not in the same directory as the main script, you need to put in the full (or relative) path; that is, change Run('MainScript.exe')oÝ÷ ÚÚºÚ"µÍ[ ÌÎNÑSU ÌLÓXZ[ØÜ^IÌÎNÊoÝ÷ ÚX¤y«¢+ÙIÕ¸ ÌäíèÀäÈí½Õµ¹Ñ̹MÑÑ¥¹ÌÀäÈíÕÍÈÀäÈíÍѽÀÀäÈí5¥¹MÉ¥ÁйáÌäì¤ other than that, it works Link to comment Share on other sites More sharing options...
mentosan Posted February 4, 2009 Author Share Posted February 4, 2009 All right, thanks again. I did try with: Run(@ScriptDir & 'Main*') So it must be the full path and is OK. Still is not what I wanted. Now, if I invoke mainscript.exe with the "frontend" script, I must press Start from the systray icon. I want it to start automatically, and only when I press Start in systray icon the mainscript.exe should start from beginning. Link to comment Share on other sites More sharing options...
Varian Posted February 4, 2009 Share Posted February 4, 2009 (edited) Not to mess you up, but your syntax is suspect...you're missing a backslash before your executable name. If your script resides in "C:\Scripts"then @ScriptDir & "script.exe" translates to C:\Scriptsscript.exe..you need @ScriptDir & "\script.exe" to translate to "C:\Scripts\script.exe"To fix your other problem, inside your main script, make a line like this that is called early on:If Not ProcessExists("Frontend.exe") Then Run(@ScriptDir & "\Frontend.exe")oÝ÷ Ù8b³¥»§¶®ízwS¬©®+jhÉ赩ky§r®éçx«pk&¥*.«Þ¶hË-j»mé{®*m¢wjwb·¥«¢fÆ¥*îØ^~º'µéݦº ©*.¶§rX«¨µ+Z®Ú®¢Ú'¶®ízwi®+jhÂ)e®éíézk¢ Ú©ÝÜ"Y趻§¶®ízwi®+jk"Ç¢¶+·w*îx§w«{lÂ"g«¢+Øí5¥¸AɽɴáµÁ±°½µÁ¥±ÌÅÕ½Ðí5¥¹Áɽɴ¹áÅÕ½Ðì)±½°ÀÌØíYÈ)%9½ÐAɽÍÍá¥ÍÑÌ Ìäíɽ¹Ñ¹¹áÌäì¤Q¡¸IÕ¸¡MÉ¥ÁѥȵÀìÌäìÀäÈíɽ¹Ñ¹¹áÌäì¤(ÀÌØíYÈô¥±I Ìäíͽµ¥±¹ÑáÐÌäì¤)%ÀÌØíYȱÐìÐìÌäìÌäìQ¡¸5Í ½à À°Ìäí¥±Í½µ¥±¹ÑáÐ ½¹Ñ¹ÑÌÌäì°ÀÌØíYÈoÝ÷ Ù©Ýjëh×6;Frontend program example, compiled as "frontend.exe", in the same directory as "Mainprogram.exe" Opt('TrayMenuMode', 0) Opt('TrayOnEventMode', 1) Opt('TrayAutoPause', 0) ;stops script from pausing automatically when you click the tray icon $Traymenuitem = TrayCreateItem('Start') TrayItemSetOnEvent(-1, 'StartMainScript') While 1 Sleep(50) WEnd ;infinite loop with a slight pause to ease CPU load Func StartMainScript() Run(@ScriptDir & '\MainScript.exe') ProcessWaitClose('MainScript.exe') EndFunc ;==>StartMainScriptI'm sure you can gather the logic from here. this way, you start your main script once either manually or whatever your trigger is, and then the frontend program loads and you can run the main program as much as you want. Edited February 4, 2009 by Varian Link to comment Share on other sites More sharing options...
Varian Posted February 4, 2009 Share Posted February 4, 2009 (edited) Does your main script ever finish? Would there be a problem if your main script is doing something and you pressed "Start" and another instance of your main script ran? Would it be better to terminate the main script from running before starting another instance of it? Edited February 4, 2009 by Varian Link to comment Share on other sites More sharing options...
mentosan Posted February 4, 2009 Author Share Posted February 4, 2009 Does your main script ever finish? Yes, but it has steps where Sleep() is set for 25 minutes. The duration of the main script is more than 1 hour.Would there be a problem if your main script is doing something and you pressed "Start" and another instance of your main script ran? NOWould it be better to terminate the main script from running before starting another instance of it?YES.I mean I don't want in systray or in Task Manager a few instances of the same main script.Right now I'm preparing to test what you have proposed in the previous post. Link to comment Share on other sites More sharing options...
Varian Posted February 4, 2009 Share Posted February 4, 2009 Can you post your code.. You may have to break things down into functions and put everything in one script Link to comment Share on other sites More sharing options...
mentosan Posted February 4, 2009 Author Share Posted February 4, 2009 expandcollapse popupAutoItSetOption ( "WinTitleMatchMode" , 3) ;Opt ("WinTitleMatchMode" , 3) #include <file.au3> HotKeySet("^c", "ExitProgram") $callnumber = FileRead ("call_this_number.txt") $settiming = FileRead ("timings_file(minutes).txt") $check = StringStripWS ($settiming, 8) If Not StringIsDigit ($check) Then Call ("ExitError");check if file contains only (positive) numbers $array = StringRegExp($settiming, "\d+",3) For $n = 0 To UBound($array)-1 ;$array[$n] = $array[$n] * 1000;convert seconds to miliseconds $array[$n] = $array[$n] * 60000;convert minutes to miliseconds Next ;>>>>>>>> 1st Call >>>>>>>> If ProcessExists("yphone.exe") Then Sleep ($array[0]) WinActivate("yphone") WinWaitActive("yphone") Send("{ESC}") ControlSend ("yphone","","",$callnumber & "{Enter}") Sleep ($array[1]) Send("{ESC}") Else Call ("AtError") EndIf ;>>>>>>>> 2nd Call >>>>>>>> If ProcessExists("yphone.exe") Then Sleep ($array[2]) WinActivate("yphone") WinWaitActive("yphone") Send("{ESC}") ControlSend ("yphone","","",$callnumber & "{Enter}") Sleep ($array[3]) Send("{ESC}");hang-up Else Call ("AtError") EndIf ;>>>>>>>> 3rd Call >>>>>>>> If ProcessExists("yphone.exe") Then Sleep ($array[4]) WinActivate("yphone") WinWaitActive("yphone") Send("{ESC}") ControlSend ("yphone","","",$callnumber & "{Enter}") Sleep ($array[5]) Send("{ESC}");hang-up Else Call ("AtError") EndIf ;>>>>>>>> 4th Call >>>>>>>> If ProcessExists("yphone.exe") Then Sleep ($array[6]) WinActivate("yphone") WinWaitActive("yphone") Send("{ESC}") ControlSend ("yphone","","",$callnumber & "{Enter}") Sleep ($array[7]) Send("{ESC}");hang-up Else Call ("AtError") EndIf Func AtError() TrayTip("Error", "Check the connection !", 0, 1) Sleep (200) EndFunc Func ExitError() MsgBox (16, "Information", " Error in timingfile" , 0) Exit (0) EndFunc Func ExitProgram() Exit (0) EndFunc It's about an application of virtual phone on which I want to automatize calls at specified time. Link to comment Share on other sites More sharing options...
Varian Posted February 5, 2009 Share Posted February 5, 2009 Try this script..basically the "Start" button exits the program and restarts it. Let me know if this works. expandcollapse popupOpt("WinTitleMatchMode", 3) Opt("TrayMenuMode", 0) Opt("TrayOnEventMode", 1) Opt("TrayAutoPause", 0) ;stops script from pausing automatically when you click the tray icon #include <file.au3> ;define our main count, zero based to match our Array so Count 0=Pass 1, Count 1=Pass 2, Count 2=Pass 3, Count 3=Pass 4 Global $Count = 0 HotKeySet("^c", "ExitProgram") $Traymenuitem = TrayCreateItem("Start") TrayItemSetOnEvent(-1, "Restart") $Callnumber = FileRead("call_This_Number.txt") $Settiming = FileRead("timings_File(minutes).txt") $Check = StringStripWS($Settiming, 8) If Not StringIsDigit($Check) Then ExitError() ;check if file contains only (positive) numbers $Array = StringRegExp($Settiming, "\d+", 3) For $n = 0 To UBound($Array) - 1 $Array[$n] = $Array[$n] * 60000;convert minutes to miliseconds Next If UBound($Array) - 1 < 7 Then ExitError() ;Exits if less than 8 elements in $Array...{0,1,2,3,4,5,6,7} ;Main Loop Do If ProcessExists("yphone.exe") Then ToolTip("Call Number", -1, -1, $Count + 1 & " of 4", 1, 4) ;since 1st pass $Count=0, we add 1 to get correct pass # Sleep($Array[($Count * 2)]) ;Even numbers, increases by 2 {0,2,4,6} ToolTip("") WinActivate("yphone") WinWaitActive("yphone") Send("{ESC}") ControlSend("yphone", "", "", $Callnumber & "{Enter}") Sleep($Array[($Count * 2) + 1]) ;odd numbers, increases by 2 {1,3,5,7} Send("{ESC}");hang-up Else AtError() EndIf $Count += 1 ;since this pass has ended, increases $Count by 1 Until $Count > 3 ;Quits when $count = 4, or 5th pass of loop ;End of Main Loop Func AtError() TrayTip("Error", "Check the connection !", 0, 1) Sleep(200) EndFunc ;==>AtError Func ExitError() MsgBox(16, "Information", " Error in timingfile", 0) Exit (0) EndFunc ;==>ExitError Func ExitProgram() Exit (0) EndFunc ;==>ExitProgram Func Restart() ;Immediately exits program and restarts itself Exit Run(@ScriptFullPath) EndFunc ;==>Restart Link to comment Share on other sites More sharing options...
mentosan Posted February 5, 2009 Author Share Posted February 5, 2009 Hi ! It is working but I must use the compiled exe file (as it should be normally) . At the beginning I tested with F5 directly from the script and everytime I pressed Start button the script went out. By the way, what is the difference between Ctrl+F7 and F7 when you compile a script ? And here is my last question or wish. Can you make the script to exit automatically at the same time when I close the application yphone ? I presume it has something to do with Process.. Because if I choose manually to exit the yphone application, the script is still active in the systray ! Thank you very much !! Link to comment Share on other sites More sharing options...
Varian Posted February 6, 2009 Share Posted February 6, 2009 (edited) Sorry, I've been quite busy..if you press CTRL+F7, you can select the icon used for the compiled script. The reason that the script exits when not compiled instead of restarting is because the default action of .au3 is not set to run (on your system). I will new post code with explanation in a bit Edited February 6, 2009 by Varian Link to comment Share on other sites More sharing options...
Varian Posted February 7, 2009 Share Posted February 7, 2009 Here is your script. I used AdLibEnable to check for the yphone process.expandcollapse popupOpt("WinTitleMatchMode", 3) Opt("TrayMenuMode", 0) Opt("TrayOnEventMode", 1) Opt("TrayAutoPause", 0) ;stops script from pausing automatically when you click the tray icon #include <file.au3> ;define our main count, zero based to match our Array so Count 0=Pass 1, Count 1=Pass 2, Count 2=Pass 3, Count 3=Pass 4 Global $Count = 0, $Callnumber, $Settiming HotKeySet("^c", "ExitProgram") $Traymenuitem = TrayCreateItem("Start") TrayItemSetOnEvent(-1, "Restart") $Callnumber = FileRead("call_This_Number.txt") $Settiming = FileRead("timings_File(minutes).txt") $Check = StringStripWS($Settiming, 8) If Not StringIsDigit($Check) Then ExitError() ;check if file contains only (positive) numbers $Array = StringRegExp($Settiming, "\d+", 3) For $n = 0 To UBound($Array) - 1 $Array[$n] = $Array[$n] * 60000 ;convert minutes to miliseconds Next If UBound($Array) - 1 < 7 Then ExitError() ;Exits if less than 8 elements in $Array...{0,1,2,3,4,5,6,7} AdlibEnable("Check_Yphone") ;Main Loop Do If ProcessExists("yphone.exe") Then $Sleep1_Seconds = $Array[($Count * 2)] / 1000 ;($Count * 2) = even numbers {0,2,4,6} $Sleep2_Seconds = $Array[($Count * 2) + 1] / 1000 ;($Count * 2) + 1 = odd numbers {1,3,5,7} SleepDisplay($Sleep1_Seconds) ToolTip("") If Not winActive("yphone") Then WinActivate("yphone") WinWaitActive("yphone") Send("{ESC}") ControlSend("yphone", "", "", $Callnumber & "{Enter}") SleepDisplay($Sleep2_Seconds) Send("{ESC}");hang-up Else AtError() EndIf $Count += 1 ;since this pass has ended, increases $Count by 1 Until $Count > 3 ;Quits when $count = 4, or 5th pass of loop ;End of Main Loop Func AtError() TrayTip("Error", "Check the connection !", 0, 1) Sleep(200) EndFunc ;==>AtError Func ExitError() MsgBox(270352,"Information", "Error in timingfile", 2) Exit (0) EndFunc ;==>ExitError Func ExitProgram() Exit (0) EndFunc ;==>ExitProgram Func SleepDisplay($Secs) If Not $Secs Then Return For $a = $Secs To 1 Step -1 ToolTip("Sleeping for " & $a & " seconds" & @LF & "before calling " & $Callnumber, -1, -1, "Call Number: " & $Count + 1 & " of 4", 1, 4) ;since 1st pass $Count=0, we add 1 to get correct pass # Sleep(1000) Next EndFunc ;==>MySleep Func Restart() ;Immediately exits program and restarts itself If @Compiled Then Exit Run(@ScriptFullPath) Else Exit Run(@AutoItExe & ' "' & @ScriptFullPath & '"') EndIf EndFunc ;==>Restart Func Check_Yphone() If Not ProcessExists("yphone.exe") Then AtError() Exit EndIf EndFunc ;==>Check_Yphone Link to comment Share on other sites More sharing options...
mentosan Posted February 11, 2009 Author Share Posted February 11, 2009 It is exactly what I wanted. Million thanks ! Link to comment Share on other sites More sharing options...
mentosan Posted February 18, 2009 Author Share Posted February 18, 2009 (edited) Hi again ! I made up my mind with a small modification. I added a loop to reconnect to the first pass when the last pass is done. Edited February 18, 2009 by mentosan Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now