Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Waiting for file save


  • Please log in to reply
6 replies to this topic
Psychobabble
  • Members
  • 2 posts
  • Last active: Sep 13 2010 02:28 AM
  • Joined: 13 Sep 2010
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!

  • Guests
  • Last active:
  • Joined: --
u can loop IfExist to check whether the file is there or not

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Along with the mentioned IfExist loop, you may check if the size of the file is changing.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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.


  • Guests
  • Last active:
  • Joined: --
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.

Psychobabble
  • Members
  • 2 posts
  • Last active: Sep 13 2010 02:28 AM
  • Joined: 13 Sep 2010
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?

  • Guests
  • Last active:
  • Joined: --

(windows mouse makes thinking symbol)

...you can detect that with AutoHotkey...quick version...

#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.

hamlin
  • Guests
  • Last active:
  • Joined: --
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