first, thanks for this FANTASTIC utility, really useful.
The macro I'm trying to make involves outputting a file at the end. The file's are reasonably large image files and take approximately 7 seconds to save. After saving this file, the macro loops a specified number of times. To make sure it doesn't get ahead of itself, i've put a 10sec pause at the end after file save. The problem is the "approximately" 7 seconds. Because I wait for 10sec, it's running quite inefficiently (which is annoying when it's repeated 100s of times) and also sometimes they take longer than 10 seconds which messes the macro up.
Is there a command I can do to wait until a file is created before moving on to the next step of the macro? I've looked through the help and can't find one.
Thanks!
Waiting for file save
Started by
Psychobabble
, Sep 13 2010 02:31 AM
6 replies to this topic
#1
-
Posted 13 September 2010 - 02:31 AM
u can loop IfExist to check whether the file is there or not
#2
-
Posted 13 September 2010 - 03:18 AM
Along with the mentioned IfExist loop, you may check if the size of the file is changing.
#3
-
Posted 13 September 2010 - 04:03 AM
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org
Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.
I actually have a script that does this, I use WinWaitClose on the Save As window. Start there, then add a couple more seconds of Sleep, if it's still not slow enough. Then, of course, use the Loop if (FileExist()) method to slow it more, if needed.
#4
-
Posted 13 September 2010 - 05:00 AM
Thanks for the ideas. The program I'm using creates the file after the save/as window is closed and then progressively embiggens it for a few seconds (windows mouse makes thinking symbol) untiil it's finished. So unfortunately neither the FileExist() nor WinWaitClose methods will work. "you may check if the size of the file is changing" would work, how would I write a loop that pauses the program until the size of the file is not changing?
#5
-
Posted 13 September 2010 - 06:05 AM
...you can detect that with AutoHotkey...quick version...(windows mouse makes thinking symbol)
#SingleInstance force CoordMode, Tooltip Sleep, 1519 Tooltip, Waiting..., 719, 519 CursorWaitChange() Tooltip, Waiting...done, 719, 519 Sleep, 3019 CursorWaitChange(p_sleep="") { if (p_sleep="") { p_sleep=319 } ;//msgbox, (%A_Cursor%) mousecursor_start:=A_Cursor Loop { if (A_Cursor!=mousecursor_start) { break } Tooltip, Sleeping...%A_Index%, 719, 538, 2 Sleep, %p_sleep% } Tooltip, , 719, 419, 2 }...I would expand that with a timeout & a "wait for specific cursor" instead of just waiting for it to change.
#6
-
Posted 13 September 2010 - 08:38 AM
As I understand it, you want to wait until the file has finished being written before exiting your script. A very simple and reliable way to do this is to attempt to rename the file after starting the file write. The OS will not allow a file to be renamed while it is in use (i.e. being written). Once the write is finished, the rename will succeed.
file = some file path name FileAppend, %data%, %file% Loop { FileMove, %file%, %file% ; renames the file to the same file name if !ErrorLevel ; if ErrorLevel = 0 the file write is complete break sleep, 250 ; kill some time before checking again } msgbox, Finished
#7
-
Posted 13 September 2010 - 11:19 AM