OnEvent TIME problem 13.x

General Macro Scheduler discussion

Moderators: JRL, Dorian (MJT support)

Post Reply
cabaptista
Newbie
Posts: 2
Joined: Wed Feb 29, 2012 8:51 am

OnEvent TIME problem 13.x

Post by cabaptista » Wed Feb 29, 2012 8:57 am

Hi everyone,

I could use a little help with the following code.
The OnEvent>TIME... is not working and i don´t know why. ;)

Code: Select all

Let>appTitle=N.A. Shutdown
Let>appQuit=0
AddTrayIcon>%SCRIPT_DIR%\Gray.ico,trayIcon,%appTitle%%CRLF%Scheduler not set
AddTrayHandler>trayIcon,OnClick,TrayIconClick
While>appQuit=0
    Wait>0.1
EndWhile
Exit>0

SRT>TrayIconClick
    Let>popupMenuItems=Shutdown Now;Shutdown in 5 minutes;-;Exit
    GetCursorPos>xPos,yPos
    PopupMenu>xPos,yPos,popupMenuItems,popupMenuResult
    
    If>popupMenuResult=0
        ModTrayIcon>trayIcon,%appTitle%%CRLF%Windows is shuting down...,%SCRIPT_DIR%\Red.ico,True
        Wait>5
        ShutDownWindows>3
    EndIf
    If>popupMenuResult=1
        GetDate>currentDate
        GetTime>currentTime
        TimeAdd>currentTime,M,1,shutdownTime
        TimePart>currentTime,H,currentHour
        TimePart>shutdownTime,H,shutdownHour
        Let>laterDay=0
        If>shutdownHour<currentHour>laterDay=1
        Else
            TimePart>currentTime,M,currentMinute
            TimePart>shutdownTime,M,shutdownMinute
            If>shutdownMinute<currentMinute>laterDay=1
            EndIf
        EndIf
        If>laterDay=1
            DateAdd>currentDate,D,1,currentDate
        EndIf
        TimePart>shutdownTime,H,shutdownHour
        If>shutdownHour<10>shutdownHour=0%shutdownHour%
        EndIf
        TimePart>shutdownTime,M,shutdownMinute
        If>shutdownMinute<10>shutdownMinute=0%shutdownMinute%
        EndIf
        Let>WIN_SLEEP=1
        OnEvent>TIME,%shutdownHour%%shutdownMinute%,,TimeEvent
        ModTrayIcon>trayIcon,%appTitle%%CRLF%Windows will shutdown at %currentDate% %shutdownHour%:%shutdownMinute%,%SCRIPT_DIR%\Red.ico,True
    EndIf
    If>popupMenuResult=3
        DelTrayIcon>trayIcon
        Let>appQuit=1
    EndIf
END>trayIconClick
 
SRT>TimeEvent
    Message>Go
    //If>popupMenuResult<0>5
    //  ShutDownWindows>3
    //EndIf
END>TimeEvent
Thanks in advance.

César Baptista

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Feb 29, 2012 6:58 pm

I think this is what you want to do. Your if statements are not going to work as you have them. They need to be rewritten as complex expressions. But in this case I think its easier to use vbscript. There was nothing wrong with your onevent except that it was at certain times of th day not receiving a four digit time

Code: Select all

Let>appTitle=N.A. Shutdown
Let>appQuit=0
AddTrayIcon>%SCRIPT_DIR%\Gray.ico,trayIcon,%appTitle%%CRLF%Scheduler not set
AddTrayHandler>trayIcon,OnClick,TrayIconClick
While>appQuit=0
    Wait>0.1
EndWhile
Exit>0

SRT>TrayIconClick
    Let>popupMenuItems=Shutdown Now;Shutdown in 5 minutes;-;Exit
    GetCursorPos>xPos,yPos
    PopupMenu>xPos,yPos,popupMenuItems,popupMenuResult
    
    If>popupMenuResult=0
        ModTrayIcon>trayIcon,%appTitle%%CRLF%Windows is shuting down...,%SCRIPT_DIR%\Red.ico,True
        Wait>5
        ShutDownWindows>3
    EndIf
    If>popupMenuResult=1
        VBStart
        VBEND
        VBEval>Right("0" & Hour(now),2) & (Right("0" & Minute(now),2) + 1),shutdownTime
    
/*
        GetDate>currentDate
        GetTime>currentTime
        TimeAdd>currentTime,M,1,shutdownTime
        TimePart>currentTime,H,currentHour
        TimePart>shutdownTime,H,shutdownHour
        Let>laterDay=0
        If>shutdownHour<currentHour>laterDay=1
        Else
            TimePart>currentTime,M,currentMinute
            TimePart>shutdownTime,M,shutdownMinute
            If>shutdownMinute<currentMinute>laterDay=1
            EndIf
        EndIf
        If>laterDay=1
            DateAdd>currentDate,D,1,currentDate
        EndIf
        TimePart>shutdownTime,H,shutdownHour
        If>shutdownHour<10>shutdownHour=0%shutdownHour%
        EndIf
        TimePart>shutdownTime,M,shutdownMinute
        If>shutdownMinute<10>shutdownMinute=0%shutdownMinute%
        EndIf
*/
        Let>WIN_SLEEP=1
        OnEvent>TIME,%shutdownTime%,,TimeEvent
        ModTrayIcon>trayIcon,%appTitle%%CRLF%Windows will shutdown at %currentDate% %shutdownHour%:%shutdownMinute%,%SCRIPT_DIR%\Red.ico,True
    EndIf
    If>popupMenuResult=3
        DelTrayIcon>trayIcon
        Let>appQuit=1
    EndIf
END>trayIconClick
 
SRT>TimeEvent
    Message>Go
    //If>popupMenuResult<0>5
    //  ShutDownWindows>3
    //EndIf
END>TimeEvent

cabaptista
Newbie
Posts: 2
Joined: Wed Feb 29, 2012 8:51 am

Post by cabaptista » Thu Mar 01, 2012 12:55 am

I got the idea. ;)

Thanks.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts