Jump to content

Seeking input - first script


atomman
 Share

Recommended Posts

First i have to say that AutoIt is an incredible little app! I always wanted to learn to write some language, but i always ran into 2 road blocks; 1) not having an application for the code and 2) i absolutely cannot sit and read through long, boring manuals. I've tried Java NetBeans, Python (at least 3 times over the years) and a bunch of 'basic' like development applications and never wrote anything worthwhile. AU3 changed that because i find it very intuitive and, most of all, the documentation is very good! I just started playing with the examples and reading only what i needed to know, which was easy to find. What i couldn't get from the doc i got here on the forums (the INI code). I had a working script done in a few hours and have spent the last couple days playing with and refining it and learning from it. I have written my very first GUI (with code behind it this time) and am really excited! The door has been opened!

I'd like to post the script here for review. Since this is my first script, i'm certain i made fundamental errors and i'd like input.

This script was created for the purpose of automating a bunch of mouse clicks and key presses when editing news for my website using KompoZer and Firefox. It seems to work extremely well.

I don't like having to use 'MouseMove', but KompoZer (Mozilla based NVU bug fix) doesn't provide control ID's.

Oh, one thing i am having trouble with is 'ExitLoop'. I'm expecting it to simply exit the loop and let the GUI open, but instead it closes it.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.8.1
 Author: atomman

 Script Function: GUI for automating blog editing(works only with KompoZer and Firefox)

#ce ----------------------------------------------------------------------------

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=c:\apps\koda\forms\dw edit form.kxf
GUICreate("dwedit", 154, 24, IniRead("config.ini", "GUI", "X-Pos", 0), IniRead("config.ini", "GUI", "Y-Pos", 0), BitOR($WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS), BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE))
$ButHLFormat = GUICtrlCreateButton("Link/Style", 2, 2, 60, 20, $BS_FLAT)
GUICtrlSetTip(-1, "Apply link and style")
$ButExit = GUICtrlCreateButton("X", 107, 2, 19, 21, $BS_FLAT)
GUICtrlSetTip(-1, "Close")
GUICtrlCreateLabel("", -642, -619, 160, 24, BitOR($SS_NOPREFIX,$SS_CENTERIMAGE,$SS_RIGHTJUST,$SS_SUNKEN,$WS_GROUP,$WS_TABSTOP,$WS_HSCROLL,$WS_VSCROLL,$WS_BORDER,$WS_CLIPSIBLINGS), $GUI_WS_EX_PARENTDRAG)
GUICtrlCreatePic("drag.gif", 132, 2, 20, 20, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS), $GUI_WS_EX_PARENTDRAG)
GUISetState()
#EndRegion ### END Koda GUI section ###

; SET AUTOIT OPTIONS
Opt("WinTitleMatchMode", 2)
Opt("SendKeyDownDelay", 20)
Opt("MouseClickDelay", 5)
Opt("MouseClickDownDelay", 5)

While 1
    
    Local $pos;get last window position from .ini
    $pos = WinGetPos("dwedit")

    $msg = GUIGetMsg()

    IF WinActive("KompoZer") Then
        WinSetOnTop("dwedit", "", 1)
    Else
        WinSetOnTop("dwedit", "", 0)
    EndIf

    Select
        Case $msg = $ButHLFormat
            If (WinExists("Mozilla Firefox") And WinExists("KompoZer")) Then
                WinActivate("Mozilla Firefox")
                WinWaitActive("Mozilla Firefox")
                Send("^l");select URL
                Send("^c");copy URL
                WinActivate("KompoZer")
                WinWaitActive("KompoZer")
                WinSetState("KompoZer", "", @SW_MAXIMIZE)
                Send("^l");insert link
                WinWaitActive("Link Properties")
                Send("^v")  ;paste copied link
                Send("{ENTER}");close link dialog and create hyperlink
                WinWaitActive("KompoZer")
                MouseMove(180, 80, 0);move to CSS menu
                MouseClick("left")  ;open CSS menu
                MouseMove(180, 160, 0);move to CSS style
                MouseClick("left")  ;select and apply style
                Send("{RIGHT}")     ;unhighlight text
                Send("{ENTER 2}")   ;start new line
                WinActivate("Mozilla Firefox")
            Else
                MsgBox(64, "Error", "Firefox/KompoZer not running")
                ExitLoop
            EndIf
        Case $msg = $ButExit
            Exit
    EndSelect
WEnd

; SAVE LAST WINDOW POSITION
Func OnAutoItExit()
    IniWrite("config.ini", "GUI", "X-Pos", $pos[0])
    IniWrite("config.ini", "GUI", "Y-Pos", $pos[1])
EndFunc
Edited by atomman
Link to comment
Share on other sites

Welcome! It's clean cut and looks good. For me personally when waiting with winwaitactive I like to add a timeout in case something happens I didn't expect ... to keep it from just sitting there. The loop is needed as that is what is keeping the script running and thus showing the gui. Basically if you don't want it to do anything but still show the gui you just need to continue the loop. Best way to learn is to do. I like it. Cheers

Link to comment
Share on other sites

Oh, one thing i am having trouble with is 'ExitLoop'. I'm expecting it to simply exit the loop and let the GUI open, but instead it closes it.

The GUI closes, because the WHILE loop is keeping it open. If you have a look at all the GUI examples, they all have one. Its just what needs to be done :)

Link to comment
Share on other sites

Thanks guys!

Burt, i'm not sure what you meant, even after thinking on it and reading the help doc. However, i changed 'While' to 'Do' and made a few other changes and now it's doing exactly what i want.

I meant they all have some sort of loop to keep it open :) glad to hear its working...

Oh yea... its Bert or Brett :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...