Diana (Cda) Posted July 20, 2008 Share Posted July 20, 2008 (edited) In "cleaning up" this script, I must have done something wrong. Have gone through with fine-tooth comb, but don't know how to fix. This here:expandcollapse popup; ; AutoIt 3x ; #Include<_SYSTRAY, refresh.au3> #NoTrayIcon ; AutoIt's icon doesn't show in systray TraySetIcon(@ScriptDir & "\PUAC- 01- start PUAC (+loops).ico") ;===== Start new systray script: ================================================================= ; Systray button commands here: Opt("GuiOnEventMode", 1) Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) ;------------------------------------------------------------------------- TrayCreateItem("Start PUAC") TrayItemSetOnEvent(-1, "_StartPUAC") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "_Quit") ; Functions for the buttons above follow within the GUI code found near bottom, below. ;================================================================================================== ;----------------------------------------------------------------------------------- $oSp = ObjCreate("SAPI.SpVoice") $oSp.Speak("Closing poo ack, and starting up tray script.") ; voice prompt for this PUAC script. Sleep(1000) ;----------------------------------------------------------------------------------- Beep(1500,50) Beep(1000,75) Beep(1500,50) Beep(1000,75) If ProcessExists("Puac.exe") Then ProcessClose ("Puac.exe") _RefreshSystemTray() ; removes lingering icons from systray after PUAC close ;----------------------------------------------------------------------------------- Sleep(1500) While 1 SoundPlay(@ScriptDir & "\WAV-PrPrint.wav") Sleep(2500) Func _StartPUAC() Sleep(500) $oSp.Speak("Launching poo ack, if it isn't already running.") ; voice prompt for this PUAC script. Sleep(1000) GUISetIcon(@ScriptDir & "\PUAC- 01- start PUAC (+loops).ico") SoundPlay(@ScriptDir & "\WAV-Wookie.wav") $SamePartition = StringLeft(@ScriptDir, 2) If NOT ProcessExists("Puac.exe") Then ShellExecute($SamePartition & "\alarm,TaskScheduler - PUAC v2.0.7\APP- PUAC v2.0.7\Puac.exe") Sleep(1500) Exit ; finished EndFunc ;==>_Continue Func _Quit() Exit ; finished EndFunc ;==>_QuitExit Sleep (5000) ; Sleep for 1,800,000 = 30 minutes / 60,000 units = 1 minute / 30,000=30 seconds / 15,000=15 seconds / 10,000=10 seconds / 5,000=5 seconds WEndthe script works but then doesn't stay in residence. Thanks in advance. Hope that by seeing what fixes this one, will finally learn about what I sometimes miss re While ... WEnd. muttley Edited July 20, 2008 by Diana (Cda) Link to comment Share on other sites More sharing options...
Developers Jos Posted July 20, 2008 Developers Share Posted July 20, 2008 You cannot have a Func-EndFunc inside any loop like While-Wend, just simply not allowed. Move the Func-EndFunc to the bottom and call the Func inside the loop by doing: _StartPUAC() Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Diana (Cda) Posted July 20, 2008 Author Share Posted July 20, 2008 (edited) You cannot have a Func-EndFunc inside any loop like While-Wend, just simply not allowed. Move the Func-EndFunc to the bottom and call the Func inside the loop by doing: _StartPUAC() JosThanks, Jos. That's good to know. I was in a real bind because the script did work before I touched it today but found that I actually had an older version before which wasn't easy to recognize as I didn't know this about no Func-EndFunc inside While-WEnd. I screwed up, in other words by providing wrong script. I have to look at it in a positive way - extra practice for me <g>. Anywho, got even more practice by cleaning up this one, the _right_ one, and here it is as it stands now:expandcollapse popup; ; AutoIt 3x ; #Include<_SYSTRAY, refresh.au3> #NoTrayIcon ; AutoIt's icon doesn't show in systray ;------------------------------------------------------------------------- $oSp = ObjCreate("SAPI.SpVoice") $oSp.Speak("Closing poo ack, and starting up tray script.") ; voice prompt for this PUAC script. Sleep(1000) ;------------------------------------------------------------------------- If ProcessExists("Puac.exe") Then ProcessClose ("Puac.exe") _RefreshSystemTray() ; refreshes the systray of lingering icons after PUAC close ;---------------------------------------------------------------------------------------------------------------------------------------------------- ;---------------------------------------------------------------------------------------------------------------------------------------------------- ;----- Tray script: --------------------------------------------------------------------------------------------------------------------------------- #include <GuiConstants.au3> #NoTrayIcon ; AutoIt's icon doesn't show in systray TraySetIcon(@ScriptDir & "\PUAC- 02- _CLOSE_ PUAC + and start tray script (+loops).ico") Beep(1000,100) Beep(750,200) Beep(1000,100) Beep(750,200) Beep(1000,100) Beep(750, 25) Beep(1000,100) Beep(750,200) ;===== Tray "context" menu items: ======================================== Opt("GuiOnEventMode", 1) Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) ;------------------------------------------------------------------------- TrayCreateItem("Start PUAC") TrayItemSetOnEvent(-1, "_StartPUAC") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "_Quit") ;========================================================================= While 1 $fStartPUAC = False ; <=== Bug fix, reset continue flag to prevent constant beeping (holdover syntax from older script that still seems to work here) WEnd Func _StartPUAC() Sleep(500) $oSp.Speak("Launching poo ack, if it isn't already running.") ; voice prompt for this PUAC script. Sleep(1000) GUISetIcon(@ScriptDir & "\PUAC- 01- start PUAC (+loops).ico") SoundPlay(@ScriptDir & "\WAV-Wookie.wav") $SamePartition = StringLeft(@ScriptDir, 2) If NOT ProcessExists("Puac.exe") Then ShellExecute($SamePartition & "\alarm,TaskScheduler - PUAC v2.0.7\APP- PUAC v2.0.7\Puac.exe") Sleep(1500) Exit ; finished EndFunc ;==>_Continue Func _Quit() Exit EndFunc ;==>_Quit I'm very curious about one thing, what is making it stay in residence in the tray? That $fStartPUAC is a holdover from someone's very kind contribution to the script initially. Yet I don't see what it's calling. When I commented out the While-WEnd with $fStartPUAC, the script does its job but winks out of the systray. So, to better understand this, why does that $fStartPUAC in While-WEnd keep the script in the systray, pls (besides because it's within the While-WEnd)? Thanks!!! muttley Edited July 20, 2008 by Diana (Cda) Link to comment Share on other sites More sharing options...
Developers Jos Posted July 20, 2008 Developers Share Posted July 20, 2008 (edited) The While-Wend loop keeps the Script active till a option on the systray menu is selected. I would add a Sleep(10) in there to minimise the CPU utilisation. I have no idea what the "$fStartPUAC = False" is doing there and doesn't seem to be used anywhere in the script. Do you also really want to exit the script when selecting "Start PUAC" ? Jos Edited July 20, 2008 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Diana (Cda) Posted July 20, 2008 Author Share Posted July 20, 2008 The While-Wend loop keeps the Script active till a option on the systray menu is selected. I would add a Sleep(10) in there to minimise the CPU utilisation.Oh, okay. Sounds kewl. I changed ...While 1 $fStartPUAC = False ; <=== Bug fix, reset continue flag to prevent constant beeping (holdover syntax from older script that still seems to work here) WEndand, you're right, still works. I upped it from 10 to 1000 in the sleep since 10 didn't seem like very much <g>. Seems to still work. I still have my "tray context menu" available from the script. I have no idea what the "$fStartPUAC = False" is doing there and doesn't seem to be used anywhere in the script.You're right. Now I know it really isn't needed any more. Do you also really want to exit the script when selecting "Start PUAC" ? JosYes. The whole idea is that when I leave home to do errands on the weekends, for example, but leave the computer on, this script stops my launcher/scheduler but puts an icon in the systray so that I can launch it again once I get home. So PUAC is turned off while this script is running in the tray. Yet when I launch PUAC with it after I get in, no longer need this script so it closes down. I have the script available in my QuickLaunch bar which I have located always just to the left of the systray rather than its default location just to the right of the start button. p.s., PUAC is another miracle freeware that launches apps, and/or speech reminders, etc. PUAC stands for "Peter's Ultimate Alarm Clock" <g>. Kewl. Thanks! Learned a lot today, again. muttley 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