Jump to content
Sign in to follow this  
Diana (Cda)

Ability in tray to re-activate a script?

Recommended Posts

Diana (Cda)

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! :)

Share this post


Link to post
Share on other sites
PsaltyDS

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.

:D

Edit: Sigh... spudw2k is handing out free fish today...

:)

Edited 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

Share this post


Link to post
Share on other sites
spudw2k

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

Share this post


Link to post
Share on other sites
Diana (Cda)

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("")

[snip]oÝ÷ Ûú®¢×ØZK­æ¥'bvÚònëHq©÷öضØb²Ú0¢¹5ÓJâGz··öÊ'zíëk©l!Ø"IèÀ®²ØZ½è­jYp®à²)Üz+]¡ë'ßÛp¢¹)®^®ºÚ"µÍÂÈ]]Ò]ÞÂÓÕ^RXÛÛÈ]]Ò]   ÌÎNÜÈXÛÛÙÛÌÎNÝÚÝÈ[ÞÝ^B^]XÛÛØÜ    [È ][ÝÉÌLÔPPËHKHÝPPÈ

ÛÛÜÊKXÛÉ][ÝÊBÜ
    ][ÝÕ^SY[S[ÙI][ÝËJHÈY][^HY[H][È
ØÜ]ÙKÑ^][Ý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ÚÈ][Û][ÝÊ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[Ú[^]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[Ú[^]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. :)

Share this post


Link to post
Share on other sites
PsaltyDS

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:

#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 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

Share this post


Link to post
Share on other sites
Diana (Cda)

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! :)

Share this post


Link to post
Share on other sites
PsaltyDS

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 = False

I 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

Share this post


Link to post
Share on other sites
Diana (Cda)

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:

;
; 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 by Diana (Cda)

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  

×