Sign in to follow this  
Followers 0
ewg

Trouble with Outlook calendar script. While/if mess

4 posts in this topic

Hi.

I'm working on a calendar-script running in Outlook for the place I work at.

We have a dedicated pc hooked up to a big monitor which hangs in the lobby-area, serving as an easy way to show todays meetings in our different meetingrooms. What I want is to spend as little time as possible with this computer, as we have plenty of other things to do ;), and so I need some automation.. I found that AutoIT would be perfect for the job, as all I need my script to do, is to check for focus, and run some simple commands every so often. However, as I've never coded as much as half a line in my life, I'm having some problems.

Here's my code, somewhat commented. Notice that I'm using Traytips for debugging, as I not yet fully understand the logic in "while()". I found this to be an easy way to check where my script stops, and it has helped me a great deal during basic-study and "development".

The script is running on the latest AutoIT version atm, and on a WinXp box.

CODE
;

; Author: ewg

; Script for Outlook Calendar-PC

; Declaring Variables/options....

Opt("WinTitleMatchMode", 2) ; I'm using "2" so I can use winactivate("Microsoft Outlook") instead of ("Meeting Room Edison - Microsoft Outlook"), because if we ever need to remote to this server to administer something, and forget to

; click that exact calendar (with the same title as in winactivate()) before logging out, the script won't work

Dim $i = "0"

;

; SCRIPT START!

;

$startscript = MsgBox(1, "Calendar-pc script // ewg", "Do you want to exec the script? Continues automatically in 5 seconds...",5)

If $startscript = 2 then

MsgBox(64, "Calendar-pc script // ewg", "Killing the script...",3)

exit

EndIf

TrayTip("Calendar-pc script // ewg", "So you wanna start Outlook? Let's roll...", 10, 1)

;Run Outlook

If Not(ProcessExists("outlook.exe")) Then

Run("C:\Program Files\Microsoft Office\Office12\outlook.exe")

TrayTip("Calendar-pc script // ewg", "Starting Outlook! Hold tight!", 10, 1)

EndIf

;

; Send the initial calendarview and select "Today".

WinActivate("Microsoft Outlook")

TrayTip("Calendar-pc script // ewg", "Selecting calendar-view...", 10, 1)

Send("!g")

Send("c")

Send("!g")

Send("o")

;the script works perfectly this far..

;

; while loop with today-check. Default tick is one tick every 5 sec for outlook window focus, and one tick every 10 minutes for "today".

; Also check for focus before executing the commands.

While $i <= 1

if not ProcessExists("outlook.exe") Then

run("C:\Program Files\Microsoft Office\Office12\outlook.exe")

TrayTip("Calendar-pc script // ewg", "Outlook is not running. Starting application...", 10, 1)

WinWaitActive("Inbox - Microsoft Outlook")

Send("!g")

Send("c")

Send("!g")

Send("o")

TrayTip("Calendar-pc script // ewg", "Outlook outlook commands has been sent..", 10, 1)

EndIf

if WinActive("Microsoft Outlook") = 1 Then

sleep (5000)

elseif WinActive("Microsoft Outlook") = 0 Then

TrayTip("Calendar-pc script // ewg", "STEALING FOCUS!", 10, 1)

WinActivate("Microsoft Outlook")

TrayTip("Calendar-pc script // ewg", "Outlook is not in calendarview - fixing...", 10, 1)

WinActivate("Microsoft Outlook") ; For some reason, I need Winactivate twice here, or else it rarely works (???)

Send("!g")

Send("c")

Send("!g")

Send("o")

; Sometimes, if I run the script, let the script do the initial phase of starting outlook, and selecting "today" in the calendar, and then open notepad, the script will sometimes just write "co" in notepad, not checking if outlook is active or anything..

; I do this to simulate for example a typical "A java update is available" pop-up box in windows, which I want my script to minimize, or at least hide, give focus back to outlook, and make sure that the correct view is showing.

sleep (5000)

EndIf

If WinActive("Microsoft Outlook") = 1 Then

Send("!g")

Send("o")

TrayTip("Calendar-pc script // ewg", "sleeping for ages...!", 10, 1)

sleep (600000) ;PROBLEM IS HERE! I want this IF to run every 10 minutes, AND at the same time have the other IFs run as often as they should (in this example, every 5 secs)

TrayTip("Calendar-pc script // ewg", "does not wooork!!", 10, 1)

EndIf

WEnd

So there it is, somewhat commented. As I said, I've never coded anything before, so bear with me.. I just feel that there are better/smarter ways to achieve what I want, and I wanna learn how I can code this more efficiantly. And most of all, how I can have independent timers.. I also tried Controlsend instead of Send to send the !g, c, o etc, but that never worked.. :(

I'll be thankful for any help you pro's may have to offer.

Regards

Erlend.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this below and let me know how it works out for you.

; Author: ewg
; Script for Outlook Calendar-PC


; Declaring Variables/options....

Opt("WinTitleMatchMode", 2) 
; I'm using "2" so I can use winactivate("Microsoft Outlook") instead 
; of ("Meeting Room Edison - Microsoft Outlook"), because if we ever need 
; to remote to this server to administer something, and forget to
; click that exact calendar (with the same title as in winactivate()) 
; before logging out, the script won't work

Dim $i = "0"


;
; SCRIPT START!
;

$startscript = MsgBox(1, "Calendar-pc script // ewg", "Do you want to exec " & _ 
    "the script? Continues automatically in 5 seconds...", 5)

If $startscript = 2 Then
    MsgBox(64, "Calendar-pc script // ewg", "Killing the script...", 3)
    Exit
EndIf

TrayTip("Calendar-pc script // ewg", "So you wanna start Outlook? Let's roll...", 10, 1)

;Run Outlook

If Not (ProcessExists("outlook.exe")) Then
    Run("C:\Program Files\Microsoft Office\Office12\outlook.exe")
    TrayTip("Calendar-pc script // ewg", "Starting Outlook! Hold tight!", 10, 1)
EndIf

;
; Send the initial calendarview and select "Today".


WinActivate("Microsoft Outlook")
TrayTip("Calendar-pc script // ewg", "Selecting calendar-view...", 10, 1)
If WinActive("Microsoft Outlook") Then
    Sleep(0030)
    Send("!g")
    Sleep(0030)
    Send("c")
    Sleep(0030)
    Send("!g")
    Sleep(0030)
    Send("o")
EndIf

; the script works perfectly this far..

;
; while loop with today-check. Default tick is one tick every 5 sec 
; for outlook window focus, and one tick every 10 minutes for "today".
; Also check for focus before executing the commands.

Global $t

While 1
    ; reiterations for 120 functions at 5 seconds = 10 minutes
    For $t = 1 to 120
        _outlook()
        $t = $t + 1
    Next
    ; will have reached 10 minutes (slightly beyond due to minor sleep delays on send keys)
    _today()    
WEnd

Func _outlook()
    If Not ProcessExists("outlook.exe") Then
        Run("C:\Program Files\Microsoft Office\Office12\outlook.exe")
        TrayTip("Calendar-pc script // ewg", "Outlook is not running. Starting application...", 10, 1)
        WinWaitActive("Inbox - Microsoft Outlook")
        If WinActive("Inbox - Microsoft Outlook") Then
            Send("!g")
            Sleep(0030)
            Send("c")
            Sleep(0030)
            Send("!g")
            Sleep(0030)
            Send("o")
            TrayTip("Calendar-pc script // ewg", "Outlook outlook commands has been sent..", 10, 1)
        EndIf
    EndIf
    If WinActive("Microsoft Outlook") Then
        Sleep(5000)
    Else
        WinActivate("Microsoft Outlook") 
        If WinActive("Microsoft Outlook") Then
            Send("!g")
            Sleep(0030)
            Send("c")
            Sleep(0030)
            Send("!g")
            Sleep(0030)
            Send("o")
            Sleep(5000)
        Else
            MsgBox(0,"Debug Line " & @ScriptLineNumber,"WinActivate for MS Outlook not working") 
        EndIf
    EndIf
EndFunc

Func _today()
    Send("!g")
    Sleep(0030)
    Send("o")
    $t = 0
EndFunc
Edited by Ealric

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Share this post


Link to post
Share on other sites

It's perfect!

I commented out the debug-box, and tried as hard as I could to break the script while it was running, but it just keeps on going, Duracell-style.

This also helped me get a better understanding of the logic behind programming, and how it is better to make a function for complex commands, rather than cramming it all inside a big while().

Thank you, Ealric! :)

Share this post


Link to post
Share on other sites

It's perfect!

I commented out the debug-box, and tried as hard as I could to break the script while it was running, but it just keeps on going, Duracell-style.

This also helped me get a better understanding of the logic behind programming, and how it is better to make a function for complex commands, rather than cramming it all inside a big while().

Thank you, Ealric! :)

Most welcome - I'm glad it worked out for you. :)


My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

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  
Followers 0