 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
planetthoughtful
Joined: 22 Feb 2006 Posts: 21
|
Posted: Wed Dec 26, 2007 6:08 pm Post subject: Wait until window / dialog fully loaded and ready for keys? |
|
|
Hi All,
I have an autohotkey script that saves the current page in firefox, adds a date/time stamp to the filename when the 'save as' dialog box opens up and then prompts me whether or not i'd like to close the page.
The problem is that approx 50% of the time, the 'Save As' box hasn't fully loaded when autohotkey decides that the window has been activated. This means that even though autohotkey then sends the timestamp string, the 'Save As' dialog isn't ready to receive it, so when the script then goes on to prompt me if I want to close the page, the 'Save As' dialog box is still open, and the original filename (without the timestamp) still appears in the 'File name' field.
So, I'm wondering if there's a way to determine if a window or dialog has fully loaded, rather than just waiting for the window to be activated?
Just to explain my current method:
1. Load page in firefox
2. Press ^m, which performs Ctrl-S
3. WinWaitActive until the 'Save As' dialog box appears
4. Send timestamp to end of filename in 'File name' field
5. Send {Enter} to actually save the file (this also closes the 'Save As' dialog)
6. Prompt with "Close current page?" (Yes / No)
The issue is turning up between steps 3 and 4, in that it appears the 'Save As' dialog is reporting that it has been activated, but because it hasn't fully loaded, it doesn't receive any of the keystrokes in steps 4 and 5, and just goes straight on to step 6.
Can anyone help me work out how to make this script behave more gracefully?
Many thanks,
pt |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Dec 26, 2007 6:12 pm Post subject: |
|
|
| What about download the page with urldownloadtofile? |
|
| Back to top |
|
 |
DerRaphael
Joined: 23 Nov 2007 Posts: 429 Location: Heidelberg, Germany
|
Posted: Wed Dec 26, 2007 9:35 pm Post subject: |
|
|
@guest - this 'll only work unless the urldownloadtofile site has no depending external files such as images, stylesheets, javascript or flash
downloading a homepage and saving it on harddisk, can be done either from curl or with wget
i personally prefer the later - its quite simple to use and abled to mirror entire sites if wished
since it is a simple commandline utility, its also easy top script. but so is cURL
back to the orgigin question:
a workaround might be to loop and check for a particular Control such as Edit1 from firefox' save dialog.
release the loop only if the control is available - this 'd make sure that your sent keys get into proper field.
| Quote: |
WinGet
--------------------------------------------------------------------------------
Retrieves the specified window's unique ID, process ID, process name, or a list of its controls. It can also retrieve a list of all windows matching the specified criteria.
| Code: |
WinGet, OutputVar [, Cmd, WinTitle, WinText, ExcludeTitle, ExcludeText]
|
ControlList: Retrieves the control names for all controls in a window. If no matching window exists or there are no controls in the window, OutputVar is made blank. Otherwise, each control name consists of its class name followed immediately by its sequence number (ClassNN), as shown by Window Spy.
Each item except the last is terminated by a linefeed (`n). To examine the individual control names one by one, use a parsing loop as shown in the examples section below.
Controls are sorted according to their Z-order, which is usually the same order as TAB key navigation if the window supports tabbing.
|
using the command nested in a condition check for the save dialog existence should do the trick
greets
derRaphael _________________
| Code: | If ((myWish="post in forum") && (!(haveAccount) || !(loggedIn))) {
MsgBox, 64, Forum Hint, It's a good idea to sign up and/or login to post in forum!
} else if ((RTFM) && (searchedForum) && (usesBrain)) {
Send, %Request%
} |
|
|
| Back to top |
|
 |
svi
Joined: 09 Oct 2006 Posts: 124 Location: Finland
|
Posted: Wed Dec 26, 2007 9:57 pm Post subject: |
|
|
| DerRaphael wrote: | ... check for a particular Control such as Edit1 from firefox' save dialog.
release the loop only if the control is available - this 'd make sure that your sent keys get into proper field. |
To be very sure that keystrokes have been received you could use ControlGetText to check it (before sending Enter). _________________ Pekka Vartto |
|
| Back to top |
|
 |
planetthoughtful
Joined: 22 Feb 2006 Posts: 21
|
Posted: Thu Dec 27, 2007 2:47 am Post subject: Just to be clear |
|
|
Hi All,
I think there may be some information above for me to go on, but I just want to make it clear that I'm not trying to determine when the page has finished loading in firefox. I know that's a completely different problem.
My problem is happening AFTER the page has finished downloading. At that point I press ^m to execute the autohotkey script, and it's the 'Save Page As' dialog box that I'm having problems detecting when it has finished loading, and is therefore ready to take the keystrokes I am sending to add the timestamp to the end of the filename.
Thanks for all the help so far!
All the best,
pt |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1071
|
Posted: Thu Dec 27, 2007 3:50 am Post subject: |
|
|
I did a little 15-second investigation and it does indeed take a little time for firefox to pop up its 'save as' dialogue. Here's a method which checks for the appearance of the box itself on the screen
| Code: | ~^s:: ; For testing purposes (other firefox users interested in this can just copy & run this script to see it work
Coordmode, pixel, screen
PixelGetColor, pcolor, 60, 60
loop 999 ; don't loop infindefinately !!!!!!
{
PixelSearch, , ,60, 60, 60, 60, %pcolor%
If Errorlevel
break
sleep 20
}
msgbox, ok`, the "save as" dialogue is up ; also for testing purposes, the msgbox should appear at the same time as the "save as" box |
Give this a whirl. Note that it will respond to any kind of pixel change at the screen coordinates 60, 60, so try not to use this while there's animation going on at that point (iow, the pixel it's checking is right under the "d" in "edit" in the menu of a maximized firefox window, which happens to be where the title bar of the "save as" dialogue appears, so this code catches the pixel's color change) _________________ My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags |
|
| Back to top |
|
 |
DerRaphael
Joined: 23 Nov 2007 Posts: 429 Location: Heidelberg, Germany
|
Posted: Thu Dec 27, 2007 7:43 am Post subject: |
|
|
this is some full blown solution to check for save dialogue and make sure the editfield which contains filename is accessible
it takes the given filename adds some kinky timestamp to it and saves the page from firefox
| Code: |
setTitleMatchmode, 2
#IfWinActive Firefox
^m::
; Trigger the save dialogue from firefox
Send, ^s
; Wait for dialoguebox to pop up
WinWaitActive, ahk_class #32770
; Loop to get List of Controls from that dialogue
Loop
{
; get the ControlList
WinGet, CtrlList, ControlList
; Parse the list
Loop, Parse, CtrlList, `n, `r
{
; do we have a Editfield already?
If (A_LoopField="Edit1") {
breakouterLoop := 1 ; set break for outer loop
break ; break this loop
}
}
if (breakouterLoop) { ; did inner loop succeed?
break
}
}
; Get the current Filename from Editfield
ControlgetText, myFilename, Edit1
; Make a Timstamp in format YYYY-MM-DD@HH-mm
myTimeStamp := RegExReplace(A_Now, "(\d{4})(\d{2})(\d{2})(\d{2})(\d{2}).+","$1-$2-$3@$4-$5")
; Take old Filename and add TimeStamp
myNewFilename := RegExReplace(myFilename, "\.html","_") myTimeStamp ".html"
; Set Focus to EditControl if not already set
ControlFocus, Edit1
; Send new timestamped Filename and save the page
Send, %myNewFilename%{Enter}
MsgBox,33,Question, Should i close the Tab?
IfMsgBox, OK
Send, ^F4
return
|
this is just the solution i was talking about in my previous post
greets
derRaphael _________________
| Code: | If ((myWish="post in forum") && (!(haveAccount) || !(loggedIn))) {
MsgBox, 64, Forum Hint, It's a good idea to sign up and/or login to post in forum!
} else if ((RTFM) && (searchedForum) && (usesBrain)) {
Send, %Request%
} |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|