Diana (Cda) Posted May 2, 2008 Share Posted May 2, 2008 I have absolutely no idea what this might be called, it just would be so neat to have the ability to "re-activate" a script that is sitting in the tray for x number of minutes with an added option in the "context menu" tray option. To explain, a particular script of mine sits in the tray for 30 minutes by way of a While>WEnd with the wait in between. The additional tray right-click option besides "Script paused" and "Exit" would be something like "Script open", or "Script re-activate" or whatever. Clicking on this would make the script stop the looping and would make the script continue as it does when the 30 mins are up and before looping if there is no user input. Is a systray option like this at all possible in AI? Thanks! Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 2, 2008 Share Posted May 2, 2008 (edited) I have absolutely no idea what this might be called, it just would be so neat to have the ability to "re-activate" a script that is sitting in the tray for x number of minutes with an added option in the "context menu" tray option.To explain, a particular script of mine sits in the tray for 30 minutes by way of a While>WEnd with the wait in between. The additional tray right-click option besides "Script paused" and "Exit" would be something like "Script open", or "Script re-activate" or whatever. Clicking on this would make the script stop the looping and would make the script continue as it does when the 30 mins are up and before looping if there is no user input.Is a systray option like this at all possible in AI?Thanks! That wouldn't even be difficult. Enable the Event mode for the Tray. Have your loop check a Global variable and exit the loop if the variable is set to a certain value (i.e. $fRun = True, or $fPause = False). Add a "continue" option to the tray menu and a function that changes the flag variable for the event when it gets clicked.You've been around here long enough to try it yourself without any demo code here. Edit: Sigh... spudw2k is handing out free fish today... Edited May 2, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
spudw2k Posted May 2, 2008 Share Posted May 2, 2008 From the help file. #Include <Constants.au3> #NoTrayIcon Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. $settingsitem = TrayCreateMenu("Settings") $displayitem = TrayCreateItem("Display", $settingsitem) $printeritem = TrayCreateItem("Printer", $settingsitem) TrayCreateItem("") $aboutitem = TrayCreateItem("About") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $aboutitem Msgbox(64,"about:","AutoIt3-Tray-sample") Case $msg = $exititem ExitLoop EndSelect WEnd Exit Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
Diana (Cda) Posted May 3, 2008 Author Share Posted May 3, 2008 From the help file. expandcollapse popup#Include <Constants.au3> #NoTrayIcon Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown. $settingsitem = TrayCreateMenu("Settings") $displayitem = TrayCreateItem("Display", $settingsitem) $printeritem = TrayCreateItem("Printer", $settingsitem) TrayCreateItem("") [snip]oÝ÷ Ûú®¢×ØZKæ¥'bvÚònëHq©÷öضØb²Ú0¢¹5ÓJâGz··öÊ'zíëk©l!Ø"IèÀ®²ØZ½èjYp®à²)Üz+]¡ë'ßÛp¢¹)®^®ºÚ"µÍÂÈ]]Ò]ÞÂÓÕ^RXÛÛÈ]]Ò] ÌÎNÜÈXÛÛÙÛÌÎNÝÚÝÈ[ÞÝ^B^TÙ]XÛÛØÜ [È ][ÝÉÌLÔPPËHKHÝPPÈ ÛÛÜÊKXÛÉ][ÝÊBÜ ][ÝÕ^SY[S[ÙI][ÝËJHÈY][^HY[H][È ØÜ]ÙKÑ^] HÚ[ÝHÚÝÛÚ[HBBÌÍÐÛÛ[YTØÜH^PÜX]R][J ][ÝÐÛÛ[YHØÜ ][ÝÊB^PÜX]R][J ][ÝÉ][ÝÊBÌÍÑ^]ØÜH^PÜX]R][J ][ÝÑ^] ][ÝÊBÛÝ[^JØÜ [È ][ÝÉÌLÕÐUT[Ø]][ÝÊBÛY L BÌÍÛÔÜHØÜX]J ][ÝÔÐTKÜÚXÙI][ÝÊBÌÍÛÔÜÜXZÊ ][ÝÜÛÈXÚÈ]YÝ[Û][ÝÊHÈÚXÙHÛÜÈPPÈØÜÛY L BYÝÑXÛY ][ÝÚSÙÐÞ[ÝÙ][ÝÊH[ØØ[ ÌÍÚSÙÐÞ[ÝÙÌÍÚSÙÐÞ[ÝÙHÙÐÞ ÌË ][ÝÔPPËÝ]YÙÈÕÈÞ[YÈÝ][ÙXÛÛËI][ÝË ][ÝÑÈ[ÝHØ[ÈÝPPÏÉ][ÝÈ [ÈÔ [ÈÔ [È ][ÝÊÈ[Z[ÈÙ]ÈÛÜÛÈ]Ú[][[[ÝHÜÈÐSÑSI][ÝË HÈ[X][ÈÈÙZ[ËYÜHÞ[YÈÝ]Ù[XÝPØÙH ÌÍÚSÙÐÞ[ÝÙHHÓÒÂBBQÕRTÙ]XÛÛØÜ [È ][ÝÉÌLÔPPËHKHÝPPÈ ÛÛÜÊKXÛÉ][ÝÊBBBTÛÝ[^JØÜ [È ][ÝÉÌLÕÐUUÛÛÚÚYKØ]][ÝÊBBBIÌÍÔØ[YT][ÛHÝ[ÓY ØÜBBBRYÕØÙÜÑ^ÝÊ ][ÝÔXXË^I][ÝÊH[Ú[^XÝ]J ÌÍÔØ[YT][Û [È ][ÝÉÌLØ[KÚÔØÚY[HPPÈÉÌLÐTHPPÈÉÌLÔXXË^I][ÝÊBBBTÛY ML BBBQ^]È[ÚYPØÙH ÌÍÚSÙÐÞ[ÝÙHÐØ[Ù[BBQ^]PØÙH ÌÍÚSÙÐÞ[ÝÙHLHÕ[Y[Ý]PØÙH ÌÍÛÙÈH ÌÍÐÛÛ[YTØÜÈÈÙÛÌÎNÝÙY[HYÚ[ÝXYÙKÝ[ÈHØÜXHÈÞ[^H X][ÈHÒÈXÝJKÝÈÈ ][ÝÙÙ]Ý] ][ÝÈÙHÛÜ[ÝXYÏÂBBQÕRTÙ]XÛÛØÜ [È ][ÝÉÌLÔPPËHKHÝPPÈ ÛÛÜÊKXÛÉ][ÝÊBBBTÛÝ[^JØÜ [È ][ÝÉÌLÕÐUUÛÛÚÚYKØ]][ÝÊBBBIÌÍÔØ[YT][ÛHÝ[ÓY ØÜBBBRYÕØÙÜÑ^ÝÊ ][ÝÔXXË^I][ÝÊH[Ú[^XÝ]J ÌÍÔØ[YT][Û [È ][ÝÉÌLØ[KÚÔØÚY[HPPÈÉÌLÐTHPPÈÉÌLÔXXË^I][ÝÊBBBTÛY ML BPØÙH ÌÍÛÙÈH ÌÍÑ^]ØÜBQ^]ÛÜ[Ù[XÝÛY N HÈÛYÜKHÌZ[]ÈÈ []ÈHHZ[]HÈÌLÌÙXÛÛÈÈMKLMHÙXÛÛÈÈLLLÙXÛÛÈÈ KMHÙXÛÛÂÑ[ I really tried to incorporate the bits about the tray into my present script but I know that I don't have it right as after I press "Continue script" once in the systray, it stops working. In other words, it only will do the "continue script" once whereas if it times out, this option should then work again once the message box disappears. The "exit" tray option doesn't work either. Also, I didn't know how to "re-activate" the script, get it out of the loop. I ended up just repeating the same syntax for the OK in the $ContinueScript portion. This doesn't seem right to me, but I just don't know how to do complex things in AI. Was hoping some patient soul might help out. I know that I'm dumb at this, I've never pretended otherwise <g>. Thanks! Appreciate any help, as always. Cheers. Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 3, 2008 Share Posted May 3, 2008 (edited) I really tried to incorporate the bits about the tray into my present script but I know that I don't have it right as after I press "Continue script" once in the systray, it stops working. In other words, it only will do the "continue script" once whereas if it times out, this option should then work again once the message box disappears. The "exit" tray option doesn't work either. Also, I didn't know how to "re-activate" the script, get it out of the loop. I ended up just repeating the same syntax for the OK in the $ContinueScript portion. This doesn't seem right to me, but I just don't know how to do complex things in AI. Was hoping some patient soul might help out. I know that I'm dumb at this, I've never pretended otherwise <g>. Thanks! Appreciate any help, as always. Cheers. Don't use Sleep() for your delays. Instead use a While/WEnd loop and TimerInit()/TimerDiff() to control the time. Because the idle loop keeps running, it can detect the changed state of the flag variable I mentioned and take actions like exiting the loop. Edit: Add demo of Tray menu in event mode: expandcollapse popup#include <GuiConstants.au3> Opt("GuiOnEventMode", 1) Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) TrayCreateItem("Continue") TrayItemSetOnEvent(-1, "_Continue") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "_Quit") Global $iTimer, $iTimeRemaining = 30 Global $fContinue = False Global $hGUI = GUICreate("Test", 200, 300) GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") Global $ctrlLabel = GUICtrlCreateLabel("Beeping in: " & $iTimeRemaining & " sec", 20, 20, 160, 20) GUISetState() While 1 $iTimeRemaining = 30 $iTimer = TimerInit() While 1 $iCountDown = 30 - Int(TimerDiff($iTimer) / 1000) ; Monitor 30sec countdown If $iCountDown <= 0 Or $fContinue Then ExitLoop ; Exit on time expired or tray continue If $iCountDown <> $iTimeRemaining Then ; Update display only when it changes to prevent flickering GUICtrlSetData($ctrlLabel, "Beeping in: " & $iTimeRemaining & " sec") $iTimeRemaining = $iCountDown EndIf Sleep(100) WEnd Beep(2000, 1000) $fContinue = False ; <=== Bug fix, reset continue flag to prevent constant beeping WEnd Func _Continue() $fContinue = True EndFunc ;==>_Continue Func _Quit() Exit EndFunc ;==>_Quit Edit: Bug fix added as per post below. Edited May 3, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Diana (Cda) Posted May 3, 2008 Author Share Posted May 3, 2008 Well, what do I know??!!! <lol> I'm just a persevering AI-scripting dumb-dumb <vbg>. Okay, so I shouldn't use "sleep" here. I'm learning something new today, again. This is great. That's a pretty kewl script! I figured out how to modify it down to 10 seconds to test. Something really weird was happening so needed to see what that was. After the 10 second countdown, it goes BEEP. But when you press "continue" in the tray "context menu" for this, it goes into a continuous looping beep, which isn't exactly what was needed. How come, do you know? Ideally, the script should run like this:PROMPT COUNTOWN PROMPT COUNTDOWN PROMPT COUNTOWN PROMPT COUNTDOWN (until user is at computer and can then get script to do its thing) Pressing "continue" should do something like this, using this sequence as an example: PROMPT COUNTOWN PROMPT COUNTDOWN CONTINUE EVENT (i.e., launch app) SHUT OFF SCRIPT Break countdown with tray context CONTINUE and script launches program and shuts off this looping/prompting script. This beeping text example you kindly provided works just fine on its own with: PROMPT COUNTDOWN PROMPT COUNTDOWN ... but when one presses "continue" rather than proceeding to task and shutting off script, it just does this EVENT EVENT EVENT EVENT EVENT .... See, when away from computer, I'd shut off my task launcher/reminder program since when I'm not there it isn't needed and things are launched, etc., that I don't need when I'm not there. But I'd always forget to turn it back on. This script would prompt to start PUAC (Peter's Alarm Clock) every half an hour. Problem is, without a context menu option, I'd in effect have to do all this manually re shut off the prompter script and then launch the app via a shortcut because I couldn't make till the script's prompt box came up again. Unless I happened to be near when it pops up so that it would launch app and shut off. Never happens! <g> Just trying to make life easier. PUAC handles my alarm clock events in the morning, too, and when to take my medications during the day, etc., etc., so this app is one of those I can't live without. If I can make this script work, life will again have just one more tiny detail made easy. Thanks! Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 3, 2008 Share Posted May 3, 2008 Something really weird was happening so needed to see what that was. After the 10 second countdown, it goes BEEP. But when you press "continue" in the tray "context menu" for this, it goes into a continuous looping beep, which isn't exactly what was needed. How come, do you know?Mistake on my part. After the Beep() the $fContinue flag was not reset, so it keeps exiting to timer loop immediately and beeping again. Just add this right before or after the Beep(): $fContinue = FalseI tweaked the code above. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Diana (Cda) Posted May 7, 2008 Author Share Posted May 7, 2008 (edited) Hi, thanks! I've done my best and the script works now somewhat, as is, but I'm missing the pop-up box that comes up every 30 minutes. I modified your code to the best of my ability and the script works from the extra tray command now. But it would be complete and proper if every 30 minutes the old timing-out message box would pop up as well. However, this is working now to a point:expandcollapse popup; ; AutoIt 3x ; #include <GuiConstants.au3> #NoTrayIcon ; AutoIt's icon doesn't show in systray TraySetIcon(@ScriptDir & "\PUAC- 01- start PUAC (+loops).ico") Opt("GuiOnEventMode", 1) Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) ;------------------------------------------------------------------------- SoundPlay(@ScriptDir & "\WAV-PrPrint.wav") Sleep(2500) $oSp = ObjCreate("SAPI.SpVoice") $oSp.Speak("poo ack ... question.") ; voice prompt for this PUAC script. Sleep(1000) ;------------------------------------------------------------------------- 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 WEnd Func _StartPUAC() 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 ;==>_QuitoÝ÷ Øýz-²êÞiº.¶Øb±¸r^Z¥{]7éôj»OP Thanks much!! Edited May 7, 2008 by Diana (Cda) 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