applescript - General - waiting for process to complete

Hey all,

I’m using screenflow I have scripted the workflow to the point of exporting a specific segment.


  1. How do you make the script pause to allow script to complete the current process then move forward after the export is complete?

delay works but that’s an absolute unfortunately the export time frame isn’t.

any help would be appreciated.


If you’re exporting a file then I assume it’s being written to a folder. And if that’s what you’re waiting for then you can check the size of the folder… then pause for 5 seconds or whatever… then check the folders size again. Obviously if the folder is changing size between checks then the file export is still going on. Or instead of checking the folder, you can check the file size directly if you have access to it.


You may also try something like this: -I haven’t tested it, its veery late!
Another method is described in this post.

There is a working function in this example Se below!
which I would have used if I were you. Good Luck

	tell application "System Events"
		set itsBusy to get busy status of (get properties of file "yourfile")
	end tell
	if not itsBusy then exit repeat
	delay 5
end repeat 

Originally written by Julio. from the post
McUsr cleaned up bad BBCode, and removed the info for command altogether
and didnt replace it with the System Events version because he BELIEVED that to be as errant
as the now deprecated info for command.

Checks if you can write to a file or not (if it is opened for access by other process).

f: file path, alias, posix path

isBusy("path:to:file.txt") --> false

to isBusy(f)
	set f to f as Unicode text
	if f does not contain ":" then set f to POSIX file f as Unicode text
		open for access file f with write permission
		close access result
		return false
	on error
		return true
	end try
end isBusy

Unfortunately, this doesn’t work because it looks like screenflow only writes to the file after the entire export complete. It stores the tmp file in the tmp directory (i think) so there are other files being written in that area.

I thought that might be the case. Maybe this would work…

  1. if you can figure out which folder it’s using, you can use the Finder to get the folder contents before you issue the command to start exporting.
  2. issue the export command
  3. get the folder contents again
  4. compare the folder contents to see which file is new… thus you would know what file the export is being written to
  5. check that file’s size

Something like this:

set tempFolder to path to temporary items folder as text

-- get the files before the export
tell application "Finder"
	set tempFiles to every file of folder tempFolder
	set beforeFiles to {}
	repeat with aTempFile in tempFiles
		set end of beforeFiles to aTempFile as text
	end repeat
end tell

(*==== start export process here ====*)

delay 10 -- a short delay to let the export process begin

-- get the files after the export
tell application "Finder"
	set tempFiles to every file of folder tempFolder
	set afterFiles to {}
	repeat with aTempFile in tempFiles
		set end of afterFiles to aTempFile as text
	end repeat
end tell

-- determine the new file
set exportTempFile to missing value
if afterFiles is not {} then
	repeat with aFile in afterFiles
		if aFile is not in beforeFiles then
			set exportTempFile to contents of aFile
			exit repeat
		end if
	end repeat
end if

-- check the file size and exit when it stops changing
if exportTempFile is not missing value then
	set lastSize to 0
		delay 5
		tell application "Finder" to set newSize to size of file exportTempFile
		if newSize is lastSize then
			exit repeat
			set lastSize to newSize
		end if
	end repeat
	return "The file is finished exporting!"
	return "The temp file could not be found."
end if


I have a slightly different alternative. We know that the file will eventually turn up in some directory, or I hope we do. -And we are pretty much in control of what happens in that directory, since it is dedicated.

This snippet would delay until a new file turned up in that directory, afterwards you might have used
the isBusy handler to check that the file is ready. -At least under the initial attempts. I am sure that the link to the file is just moved from the temporary items to the export folder, but -just to be sure.

set theExportFolder to (choose folder)
tell application "Finder"
	set a to count every file of entire contents of theExportFolder
end tell
” Waiting for some progress of the export operation
set b to a
repeat while b is a
	tell application "Finder"
		set b to count every file of entire contents of theExportFolder
	end tell
	delay 2
end repeat
” the scripts goes on after the export operation