Sign in to follow this  
Followers 0
FMS

If windowapears then

11 posts in this topic

Dear reader,

The problem at hand may seem easy :)

but i m still learning and hope u can put me in the right direction :)

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("This is some text.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "Do you want to save")
Send("!y")
WinWaitActive("Save As")
Send("test1.txt")
Send("{enter}")

As u can c nothing strange at this script,

But now is mine question....

What if u run for the second time this script....

u get a error message whit that the file already exist...

Is there a way to say.... example:

If window_apear(¨error - message¨) then

mess box(¨ error message has been detected, put your own file name in and press enter¨ )

Contineu loop2

else

mess box(¨ there isn´t a error ¨)

EndIf

And the second thing is.....

Can there be a sort of pauze so the user can put in his own filename and the script contineus????

in the whole script are the files put in another place afther it is saved so i need to send the file afther the save itself...???

The main thing is,... where can i find which loop number i need to put in to go further..(i think that is what i need;))

i hope someone can help me,

thnx in advanced ....

greez FMS


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Is there a way to say.... example:

If window_apear(¨error - message¨) then

mess box(¨ error message has been detected, put your own file name in and press enter¨ )

Contineu loop2

else

mess box(¨ there isn´t a error ¨)

EndIf

And the second thing is.....

Can there be a sort of pauze so the user can put in his own filename and the script contineus????

in the whole script are the files put in another place afther it is saved so i need to send the file afther the save itself...???

The main thing is,... where can i find which loop number i need to put in to go further..(i think that is what i need;))

Is this what you want?

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("This is some text.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "Do you want to save")
Send("!y")
WinWaitActive("Save As")
Send("test1.txt")
Send("{enter}")
$Count=0
While $Count<11
    Sleep(10)
    If WinExists("Save As","Do you want to replace it?") then Error()
    $Count+=1
WEnd
Msgbox(0,0,"No Error")
Exit

Func Error()
    Msgbox(0,0,"Error Message")
    Exit
EndFunc

As you can see, I created a variable that I use as a counter.. you could use For...Next so you don't need to declare the variable.

Roughly, it will wait 10x10 ms for the "replace file confirmation" dialog to appear before it decides that there is no error, because I set sleep(10).

But, you could also use TimerDiff function for more exact time.

Second question,

You could set so the script will wait until the confirmation dialog to close because user enters new filename and presses enter. You would need to use While WinExists().

And I think what you want to know is function. With function, you could tell the script where to go, just like the script above.

Hope it could be useful and I don't misunderstood you.

Good luck.

Edited by MDCT

Share this post


Link to post
Share on other sites

thnx :)

in a way u helped me enormously:)

but it was not the thing i ment...

this peace of work :) i can use in onother script of mine ;)

but the thing is ,....

the user must write his own file name....

afther the file name isn't in a conflict whit other file's the script must contineu ....

something liek this ;)

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("This is some text.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "Do you want to save")
Send("!y")
WinWaitActive("Save As")
Send("test1.txt")
Send("{enter}")
;*******************************************************
;if file conflict's whit another file
;the user can put his own file name 
;and the scripts run's again
;*******************************************************
;go back to the same notepad and.
;*******************************************************
Send("This is some more text.")
Send("and write some more.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "Do you want to save")
Send("!y")
WinWaitActive("Save As")
Send("test1.txt")
Send("{enter}")
;*******************************************************
;if file conflict's whit another file
;the user can put his own file name 
;and the scripts run's again
;*******************************************************

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

FMS,

Take a look at this:

; Set up array to hold test text
Global $aText[2]
$aText[0] = "This is some text."
$aText[1] = "This is some more text." & @CRLF & "and write some more."

$iCount = 0

; Loop until no filename chosen
While 1
    ;Run Notepad
    Run("notepad.exe")
    WinWaitActive("Untitled - Notepad")
    ; Send the text
    Send($aText[$iCount])
    ; Move index
    $iCount += 1
    ; Set default filename
    $sFileName = "test1.txt"
    ; If file exists, then ask for new name
    If FileExists($sFileName) Then
        ; Loop until the new name does not exist
        Do
            $sFileName = InputBox("Save As", "Enter a filename")
            ; Exit if Cancel pressed - no name chosen
            If @error Then Exit
        Until FileExists($sFileName) = 0
    EndIf
    ; Close NotePad
    WinClose("Untitled - Notepad")
    WinWaitActive("Notepad", "Save")
    Send("!s")
    WinWaitActive("Save As")
    ; Use default filename, or chosen replacement
    Send($sFileName)
    Send("{enter}")
WEnd

I had to change the

WinWaitActive("Notepad", "Save")

Send("!s")

lines to get it to work with my NotePad version. You may need to change it back.

The comments should be clear enough, but ask if anything is unclear.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

the user must write his own file name....

afther the file name isn't in a conflict whit other file's the script must contineu ....

Personally, in this case, I think it is better to let the system to handle the file-exists check.

Because, if the file does exist, it will show confirmation dialog anyway.

But, if you insists, Melba23 script is the way to go.

Also check this:

#690103

You could combine it with Melba23 script, so you won't have to type the folder location.

Here's example and different approach to give you more pictures. But, Melba23's method with InputBox should be better.

#include <GUIComboBoxEx.au3>
#include <Misc.au3>

Run(@AutoItExe & ' /AutoIt3ExecuteLine "FileSaveDialog(''Save As'', @FavoritesDir, ''All (*.*)'')"')
WinWaitActive("[ClASS:#32770;TITLE:Save As]")

$sPath = _OpenSaveDialog_GetPath_ComboMode("[ClASS:#32770;TITLE:Save As]")
$wPos=ControlGetpos("[ClASS:#32770;TITLE:Save As]","","Edit1")
$Tooltip=0

While 1
    Sleep(50)
    $EditText=ControlGetText("[ClASS:#32770;TITLE:Save As]","","Edit1")
    If $EditText = "" then 
        blank()
    ElseIf FileExists($sPath & '\' & $EditText) and $Tooltip<>1  Then
        Tooltip("File exists, insert different file name",$wPos[0],$wPos[1])
        $Tooltip=1
    ElseIf Not FileExists($sPath & '\' & $EditText) and $Tooltip<>2  Then
        Tooltip("File doesn't exist",$wPos[0],$wPos[1])
        $Tooltip=2
    EndIf
    Sleep(50)
WEnd

Func blank()
    Tooltip("Insert file name",$wPos[0],$wPos[1])
    While 1
        Sleep(40)
        $EditText=ControlGetText("[ClASS:#32770;TITLE:Save As]","","Edit1")
        If $EditText <> "" then ExitLoop
    WEnd
    Tooltip("")
EndFunc

Func _OpenSaveDialog_GetPath_ComboMode($sTitle="[ClASS:#32770]")
    Local $sRet_Path = "", $hCombo, $iIndex, $sCurrent_Text
    
    $hCombo = ControlGetHandle($sTitle, "", "ComboBox1")
    $iIndex = _GUICtrlComboBoxEx_GetCurSel($hCombo)
    
    For $i = $iIndex To 0 Step -1
        $sCurrent_Text = ""
        _GUICtrlComboBoxEx_GetItemText($hCombo, $i, $sCurrent_Text)
        
        If StringRegExp($sCurrent_Text, "(?i)[a-z]:") Then
            $sRet_Path = StringRegExpReplace($sCurrent_Text, "(?i).*([a-z]):\).*", "\1") & ":\" & $sRet_Path
            Return StringRegExpReplace($sRet_Path, "\\$", "")
        EndIf
        
        $sRet_Path = $sCurrent_Text & "\" & $sRet_Path
    Next
    
    $sCurrent_Text = ""
    _GUICtrlComboBoxEx_GetItemText($hCombo, $iIndex, $sCurrent_Text)
    
    If $sCurrent_Text = "" Then Return SetError(1, 0, "")
    
    Return $sCurrent_Text
EndFunc

Good luck.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi all >_<

these 2 way´s are very good way´s and I understand it all a little bit more....

But the thing is....

Mine question was born out of the idea to make a password changing GUI.

and the acual problem lies in that...

The scripts run´s in sending command´s...

alt-f

alt-f

and all that stuff :(

but when the scripts run´s it is possible that the user put´s a wrong password in the GUI.

So i thaught iff there is a possible way when a ¨wrong pass¨error message apears the user can put in the correct password.

And afther that the script run´s along....

Maybe i started mine question wrong whit the wrong example...:S

I think M23 knows where i am talking about :( because he had helped me before whit this project :D

Gr.

FMS

Maybe this helpes what i made:

Func PW_Change2()
Sleep(300)
    If ProcessExists("nlnotes.exe") Then
        ;**************************************By running application**************************************************
        ;BlockInput (1)
        Run("C:\Program Files\lotus\notes\Notes.exe")
        WinWaitActive("[CLASS:NOTES]", "")
        Send("{ALTDOWN}")
        Send("f")
        Send("y")
        Send("s")
        Send("{ALTUP}")
        send(GUICtrlRead($aInput[2][0]),1)
        Send("{enter}")
        ;************************************************What iff Pass is incorrect
        ;BlockInput (0)
        WinWaitActive("User Security")
        ;BlockInput (1)
        Send("!p")
        WinWaitActive("Lotus Notes")
        send(GUICtrlRead($aInput[2][0]),1)
        Send("{enter}")
        ;************************************************What iff Pass is incorrect
        ;BlockInput (0)
        WinWaitActive("Change Password")
        ;BlockInput (1)
        send(GUICtrlRead($aInput[0][0]),1)
        Send("{TAB}")
        send(GUICtrlRead($aInput[0][0]),1)
        ;BlockInput (0)
    Else
        ;**************************************By NOT running application*****************************************
        ;BlockInput (1)
        WinWaitClose("[CLASS:NOTES]", "")
        Run("C:\Program Files\lotus\notes\Notes.exe")
        WinWaitActive("Lotus Notes")
        send(GUICtrlRead($aInput[2][0]),1)
        Send("{enter}")
        ;************************************************What iff Pass is incorrect
        WinWaitActive("NVI Startpagina - IBM Lotus Notes")
        Send("{ALTDOWN}")
        Send("f")
        Send("y")
        Send("s")
        Send("{ALTUP}")
        send(GUICtrlRead($aInput[2][0]),1)
        Send("{enter}")
        ;************************************************What iff Pass is incorrect
        ;BlockInput (0)
        WinWaitActive("User Security")
        ;BlockInput (1)
        Send("!p")
        WinWaitActive("Lotus Notes")
        send(GUICtrlRead($aInput[2][0]),1)
        Send("{enter}")
        ;************************************************What iff Pass is incorrect
        ;BlockInput (0)
        WinWaitActive("Change Password")
        ;BlockInput (1)
        send(GUICtrlRead($aInput[0][0]),1)
        Send("{TAB}")
        send(GUICtrlRead($aInput[0][0]),1)
        ;BlockInput (0)
    EndIf

EndFunc

Is it possible to change the input because the input is send more times than 1 time as u can c

iff the pass incorrect???? ($aInput[2][0])

Edited by FMS

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

I think it is better to make the script to stay in a loop before it goes to the next step when inputting a password, instead just using WinWaitActive.

From your code above, after inputting the first password, you wrote: WinWaitActive("User Security"). It means that a window with "User Security" title will appear if the password is correct, right?

In that case, you could use loop While not winactive("User Security") or not winexists. And in that loop you could make the script to check for error message window or other methods to know if the password is wrong. Almost the same with what I wrote above, the one with timer counter.

Here, you could make the counter to increase after the script send the same password second time (because error message is shown). So, the script can pause, after 3 times or 5 times sending the wrong password, to let user inputs the password manually.

And I believe, you could use WinGetText to know what password to send. Assuming, inputbox window would prompt user differently.

And don't forget to add Sleep here-there and in the loop to reduce CPU, but too much can make your script unresponsive.

Good luck.

Share this post


Link to post
Share on other sites

Yes that´s right,WinWaitActive("User Security")is the windows that apear´s iff the pass is correct.

WinWaitActive("Lotus Notes")iff incorrect...

But i don´t understand why i shoot not wait for that window :S :(

or why i shoot have some sleep functions for CPU??? or where >_<

sorry iff all of this sounds a little noobisch but i realy want to learn :(

can u help me whit this?

GR.

FMS


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

why i shoot not wait for that window

No..no, you should wait for the window, but using different method, not WinWaitActive.

Why? Because with WinWaitActive, the script is paused to wait for the window, so the script cannot do anything, only wait for the window....

That's why you should put it in a loop, so it can do other things than just wait for a window to active.

While not WinActive("User Security")   ;Stays in a loop until "User Security" active
   Sleep(10)    ;Sleep 10 ms, to reduce CPU speed when in a loop
   If WinActive("Lotus Notes") then EnterPassword()     ;If "Lotus Notes" window active, the script will execute EnterPassword function
WEnd
;Next step....

Func EnterPassword()
   $Text=WinGetText("Password Window")   ;Get text from the password window
EndFunc

Look at the comments beside the code.

The While not WinActive("User Security") means that: as long as "User Security" is not active, it will stay in the loop and also check for "Lotus Notes". But if "User Security" is active (means the password is correct), it will get out of the loop and do "Next step".

As you can see, the loop waits for "User Security" to active and also check if "Lotus Notes" active. With WinWaitActive, it will only wait for "User Security".

Using the loop, it will not go to the next step when "User Security" is not active.

Maybe it's better to read more on While and other loops.

As for sleep, it's just to pause the script to reduce CPU usage. But on this step of the script development, I don't think you need it. And if the script doesn't take CPU too much, maybe you don't even need it.

Hope it helps. Don't forget, you can learn these using help file or search the forum.

Good luck.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

This is very usefull thnx for this >_<

I´m very thankfull for this and learned a bit more :(

Now i can build further :(

But there rises still one question....

or a problem iff u will :D

the problem is,....

Iff the password is wrong and the user put´s again a wrong pass for the second time...

How u must handle that in wingettext for further in the script?????

u don´t know when the password is good so also not when to get the text????

is there a way to go back in time like,...??? :

Iff window Lotus Notes apears(apears when pass is correct) then get text from window before where the user put´s in the correct pass???

Thnx in advanced ;)

Edited by FMS

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

Iff the password is wrong and the user put´s again a wrong pass for the second time...

How u must handle that in wingettext for further in the script?????

u don´t know when the password is good so also not when to get the text????

I don't get it. Wasn't the password inputted by the script?

You could set a counter, so if the script has tried 3 times and failed to enter the correct password, it will pause and let the user to enter the password manually. Then, the script will resume if ("User Security") is active because user entered the correct password. So basically, the script could know if user has entered the correct password or not.

is there a way to go back in time like,...??? :

Iff window Lotus Notes apears(apears when pass is correct) then get text from window before where the user put´s in the correct pass???

I don't understand what you want, it's different from what I thought you want to make.

I believe someone else could help you more.

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