Sign in to follow this  
Followers 0
happy2help

Compiled script read a au3 file

17 posts in this topic

Hi All

As the title says, I have a file I use every day, for simplicity, I have compiled it, but I keep editing the adlib section and then having to recompile it.

Can I get my compiled script to just read another au3 script and use it without absorbing it during the compile process (making it none editable).??

I could make it like a ini file, but I don't know how to tell the script to read it and use it like a function. I looked at the call function, but you can't add another file name to that (I think)

Is this possible? I do hope so as recompiling every hour or so is annoying.

Share this post


Link to post
Share on other sites



Of course. Use /AutoIt3ExecuteScript for that. It works for every possible format of your script.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Of course. Use /AutoIt3ExecuteScript for that. It works for every possible format of your script.

I already use that to run scripts at a particular moment in my compiled script, but how would I get the compiled script to use the contents of the au3 file?

example of compiled script

blah
blah
AdlibRegister("Myadlib")
more blah
blah

example of au3 file

blah
blah
Func Myadlib()
    If WinExists("Microsoft Office Excel", "A formula or sheet you") Then ;**** Excel VAT formula
        WinActivate("Microsoft Office Excel", "A formula or sheet you")
        Send("{SPACE}")
    EndIf

    If WinExists("Microsoft Office Excel - Compatibility Checker") Then ;**** Excel Compatibility Checker
        WinActivate("Microsoft Office Excel - Compatibility Checker")
        Send("+{TAB 2}{SPACE}")
        Sleep(500)
        Send("{TAB 2}{SPACE}")
    EndIf

    If WinExists("Microsoft Office Excel", "Do you want Excel to recalculate") Then ;**** Excel to recalculate
        WinActivate("Microsoft Office Excel", "Do you want Excel to recalculate")
        Send("n")
        Sleep(500)
    EndIf

    If WinExists("Microsoft Office Excel", "Data may exist in the sheet") Then ;**** Excel delete sheet
        WinActivate("Microsoft Office Excel", "Data may exist in the sheet")
        Send("{ENTER}")
        Sleep(500)
    EndIf
EndFunc   ;==>Myadlib

that is how i would like to use it, but I could have the au3 file with only if/endif statements.

Would I use it in the same way as I use #Include <file.au3> (at the top of the script)?

Share this post


Link to post
Share on other sites

You can't do that.

Every instance of AutoIt is just that; another process. Another process - another memory space. Sharing variables or functions is impossible.

Since AutoIt isn't implementing multiple-line Execute() you can't use that either.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

What data exactly are you needing to update hourly in the au3 file?

Perhaps you are travalling from A to B via P, X, and R.

Its not really hourly - just feels like it.

My compiled script runs all the time and I want to use that fact to monitor for certain windows and deal with them (the primary use for adlib).

Problem is that I keep finding more things to put in the adlib section, so have to recompile it.

Share this post


Link to post
Share on other sites

Could this work? Converting this to an ini file

Func Myadlib()
    If WinExists("Microsoft Office Excel", "A formula or sheet you") Then ;**** Excel VAT formula
        WinActivate("Microsoft Office Excel", "A formula or sheet you")
        Send("{SPACE}")
    EndIf

    If WinExists("Microsoft Office Excel - Compatibility Checker") Then ;**** Excel Compatibility Checker
        WinActivate("Microsoft Office Excel - Compatibility Checker")
        Send("+{TAB 2}{SPACE}")
        Sleep(500)
        Send("{TAB 2}{SPACE}")
    EndIf

    If WinExists("Microsoft Office Excel", "Do you want Excel to recalculate") Then ;**** Excel to recalculate
        WinActivate("Microsoft Office Excel", "Do you want Excel to recalculate")
        Send("n")
        Sleep(500)
    EndIf

    If WinExists("Microsoft Office Excel", "Data may exist in the sheet") Then ;**** Excel delete sheet
        WinActivate("Microsoft Office Excel", "Data may exist in the sheet")
        Send("{ENTER}")
        Sleep(500)
    EndIf
EndFunc   ;==>Myadlib

first=3
1="Microsoft Office Excel"
2="A formula or sheet you"
3="{SPACE}"

second=4
1="Microsoft Office Excel - Compatibility Checker"
2="+{TAB 2}{SPACE}"
3=500
4="{TAB 2}{SPACE}"

third=4
1="Microsoft Office Excel"
2="Do you want Excel to recalculate"
3="n"
4=500

forth=4
1="Microsoft Office Excel"
2="Data may exist in the sheet"
3="{ENTER}"
4=500

and then the compiled script reads the file and uses the data in a array?

Share this post


Link to post
Share on other sites

I imagine something like that will work.

Say you name your sections, something like this may work.

[section1]

[section2] etc...

then something like this

Global $sMyIniPath = @ScriptDir & "\MyIni.ini"
Myadlib()

Func Myadlib()
    $acount = IniReadSectionNames($sMyIniPath)
    If IsArray($acount) Then
        For $i = 1 To $acount[0]
            $atemp = IniReadSection($sMyIniPath, "Section" & $i)
            If WinExists($atemp[1],$atemp[2]) And $atemp[0] = 3 Then
                WinActivate($atemp[1])
                Send($atemp[3])
            ElseIf
                ;alternative code
            Else
                ;alternative code
            EndIf
        Next
    EndIf
EndFunc

or a switch case or something


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Why can't you just keep it in script form and run the au3 file directly instead of compiling it?

Share this post


Link to post
Share on other sites

Why can't you just keep it in script form and run the au3 file directly instead of compiling it?

I run it on at least 7 machines, of which i have autoit installed on only 2. So it is easier to compile it, than have loads of include files with the script.

As a temporary measure I have got the compiled script to start a seperate script which just deals with adlib functions.

Share this post


Link to post
Share on other sites

Try this,

The script should work without any problems, just make sure that the .ini file is in the same directory. (The Text file is supposed to be the Ini file)

Ini structure

[Title of Window]

Text=Some text in window

Send=Keys to send to window

Adlib.au3

Windows.txt

Share this post


Link to post
Share on other sites

Hi,

That looks great, but can you explain how the adlib.au3 works so I can see how it replaces my long-winded version?

Share this post


Link to post
Share on other sites

No problem,

The Adlib.au3 file calls the function every 250 ms. When the function is called it gets the active window's title, it then searches the ini file for a match. If it doesn't find one, the function is terminated and the script continues. If there is a match, then the script reads the section data into an array. The first variable tells the script to look for the specified text in the window using text= in ini file. This helps the script get an exact match on the window. The script then takes the keys listed in normal AU3 format from send= and sends them directly to the window. If u need a better understanding then just post and I will put comments in the au3 file for better understanding.c

Share this post


Link to post
Share on other sites

Does that me I can add to it's functionality like this

AdlibRegister("Check",250)
While 1
    Sleep(100)
WEnd

Func Check()
    $Active = WinGetTitle("[Active]")
    $Info = IniReadSection("Windows.ini",$Active)
    If @error Then
        Return
    Else
        ControlSend($Active,$Info[1][1],"",$Info[2][1])
        If $Info[3][1] <> "none" Then Sleep($Info[3][1])
        If $Info[4][1] <> "none" Then Send($Info[4][1])
        If $Info[5][1] <> "none" Then WinWait($Info[5][1])
        If $Info[6][1] <> "none" Then Send($Info[6][1])
        If $Info[7][1] <> "none" Then FileCopy("B:\Scripts\To Use\Completed.au3", "B:\Scripts\AcerLaptop\")
    EndIf
EndFunc

And windows.ini would be in this format

[]
Text=
Send=
Sleep=none
Send=none
WWait=none
Send=none
FCopy=none

[]
Text=
Send=
Sleep=none
Send=none
WWait=none
Send=none
FCopy=none

Now I just remove "none" from any of the extra options I want to use.

Am I right in thinking that the windows.ini file is reread every 250ms, so any changes would be picked up straight away.?

Share this post


Link to post
Share on other sites

Yes, you can add to the script as you like. Just make sure that everything works the way you want it too. Yes the INI file is re-scanned every 250 ms so any changes you make while the script is running will automatically take effect.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Hi, I'm stuck again ;):blink:

I'm using this function

Func Check()
    $Active = WinGetTitle("[Active]")
    TrayTip($Active, "", 10, 2)
    $Info = IniReadSection("C:\Tony\Windows.ini", $Active)
    If @error Then
        Return
    Else
        TrayTip($Active, $Info[1][1], 10, 2)
        ControlSend($Active, $Info[1][1], "", $Info[2][1])
        If $Info[3][1] <> "none" Then Sleep($Info[3][1])
        If $Info[4][1] <> "none" Then Send($Info[4][1])
        If $Info[5][1] <> "none" Then WinWait($Info[5][1], "", 5)
        If $Info[6][1] <> "none" Then Send($Info[6][1])
        If $Info[7][1] <> "none" Then FileCopy("B:\Scripts\To Use\Completed.au3", "B:\Scripts\AcerLaptop\")
        WinWaitClose($Active, $Info[1][1], 30)
    EndIf
EndFunc   ;==>Check

and have found a problem.

I have a program that uses the same title, just different text.

I have found that this only tries the first version of the title.

[Untitled - Notepad]
Text=Operation complete
Send=!fp
Sleep=none
Send=none
WWait=none
Send=none
FCopy=yes

[Untitled - Notepad]
Text=blah blah
Send=!fp
Sleep=none
Send=none
WWait=none
Send=none
FCopy=yes

With the above option, only the first would work (blah blah would never be found)

Edited by happy2help

Share this post


Link to post
Share on other sites

I have got it working with this, but I need some help cleaning it up and adding error checking

Func Check()
    $Active = WinGetTitle("[Active]") ; get current title of window
    TrayTip($Active, "", 10, 2)
    $var = IniReadSectionNames($inifile) ; find out how many sections are in inifile
;   _ArrayDisplay($var, "test")
    For $i = 1 To $var[0] - 1
        $Info = IniReadSection($inifile, $i) ; read inifile at section $i
;       _ArrayDisplay($Info, "test")
        If $Info[1][1] <> $Active Then ContinueLoop ; check if "title" is same as $Active
        TrayTip($Info[1][1], $Info[2][1], 10, 2) ; tell me what its found
        ControlSend($Info[1][1], $Info[2][1], "", $Info[3][1]) ; send title, text and send
        If $Info[4][1] <> "none" Then Sleep($Info[4][1])
        If $Info[5][1] <> "none" Then Send($Info[5][1])
        If $Info[6][1] <> "none" Then WinWait($Info[6][1], "", 5)
        If $Info[7][1] <> "none" Then Send($Info[7][1])
        If $Info[8][1] <> "none" Then FileCopy("B:\Scripts\To Use\Completed.au3", "B:\Scripts\AcerLaptop\")
        WinWaitClose($Active, $Info[1][1], 30)
    Next
EndFunc   ;==>Check

and windows.ini now looks like this

;**** Excel VAT formula
[1]
Title=Microsoft Office Excel
Text=A formula or sheet you
Send={SPACE}
Sleep=none
Send=none
WWait=none
Send=none
FCopy=none

[2]
Title=Microsoft Office Excel - Compatibility Checker
Text=
Send=+{TAB 2}{SPACE}
Sleep=500
Send={TAB 2}{SPACE}
WWait=none
Send=none
FCopy=none

;**** Excel to recalculate
[3]
Title=Microsoft Office Excel
Text=Do you want Excel to recalculate
Send=n
Sleep=500
Send=none
WWait=none
Send=none
FCopy=none

;**** Excel delete sheet
[4]
Title=Microsoft Office Excel
Text=Data may exist in the sheet
Send={ENTER}
Sleep=500
Send=none
WWait=none
Send=none
FCopy=none

;**** Pepsky Data Burning next disk
[5]
Title=Burn Data CD/DVD 5.2
Text=&Yes
Send={TAB 3}{ENTER}
Sleep=none
Send=none
WWait=Select the files or folder to be burned
Send={TAB 3}{ENTER}
FCopy=none

;**** Pepsky Data Burning start burn
[6]
Title=Burn Data CD/DVD 5.2
Text=Do you want to burn?
Send=[CLASS:Button; INSTANCE:1]
Sleep=none
Send=none
WWait=none
Send=none
FCopy=none

;**** Pepsky Data Burning Delete all of the added files and folders?
[7]
Title=Burn Data CD/DVD 5.2
Text=Delete all of the added files and folders?
Send=[CLASS:Button; INSTANCE:1]
Sleep=none
Send=none
WWait=none
Send=none
FCopy=yes

;**** Pepsky Data Burning complete
[8]
Title=Burn Data CD/DVD 5.2
Text=Burning completed successfully
Send=[CLASS:Button; INSTANCE:1]
Sleep=none
Send=none
WWait=none
Send=none
FCopy=yes

;**** Pepsky Image Burning complete
[9]
Title=Information
Text=Burning image completed
Send=[CLASS:Button; INSTANCE:1]
Sleep=none
Send=none
WWait=none
Send=none
FCopy=yes

;**** Pepsky DVD Folder Burning complete
[10]
Title=Information
Text=Burn process completed successfully
Send=[CLASS:Button; INSTANCE:1]
Sleep=none
Send=none
WWait=none
Send=none
FCopy=yes

;**** ConvertXtoDVD Operation Complete
[11]
Title=ConvertXtoDVD
Text=Operation complete
Send=[CLASS:Button; INSTANCE:1]
Sleep=none
Send=none
WWait=none
Send=none
FCopy=yes

;ssdffr
[12]
Title=Untitled - Notepad
Text=Operation complete
Send=!fp
Sleep=none
Send=none
WWait=none
Send=none
FCopy=yes

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