display dialog -close dialog

Is it possible to have a dialog that will close after something has finished

I have a script hat collects file info for a log file and that can take some time.
After that it will move the files to specific directories

The dialog has to open before the first “repeat with aFile in newfiles” and close after the first “end repeat”


set chosenfolder to choose folder with prompt "Kies een map met Leenbakker JPEG's" without invisibles

tell application "Finder"
	set newfiles to files in chosenfolder
	do shell script ("echo `date +%d-%m-%Y'   '%H:%M:%S` >> /Volumes/HD1/Images/log.txt")
end tell
repeat with aFile in newfiles
	try
		set logpath to "HD1:Images:"
		set filename to name of aFile
		set file_info to info for (aFile as alias)
		set file_creation_date to creation date of file_info
		set aFile to aFile as Unicode text
		set fnamepartone to ((characters 1 through 2 of filename) as Unicode text)
		set fnameparttwo to ((characters 1 through 3 of filename) as Unicode text)
		set folderpath to "HD1:Images:" & fnamepartone & ":" & fnameparttwo & ":"
		do shell script ("echo " & quoted form of ("Name: " & filename & " Creation Date: " & file_creation_date) & " >> /Volumes/HD1/Images/log.txt")
		try
			set folderalias to folderpath as alias
		on error
			do shell script "mkdir -p " & quoted form of ("/Volumes/HD1/Images/" & fnamepartone & "/" & fnameparttwo & "/")
		end try
	end try
end repeat
tell application "Finder"
	set newfiles to files in chosenfolder
end tell
repeat with aFile in newfiles
	try
		set filename to name of aFile
		set aFile to aFile as Unicode text
		if filename does not contain "-" then
			set fnamepartone to ((characters 1 through 2 of filename) as Unicode text)
			set fnameparttwo to ((characters 1 through 3 of filename) as Unicode text)
			set fnamepartthree to ((characters 1 through 8 of filename) as Unicode text)
			set folderpath to "HD1:Images:" & fnamepartone & ":" & fnameparttwo & ":"
			do shell script ("find " & quoted form of (POSIX path of folderpath) & " -name " & quoted form of (fnamepartthree) & "_*" & " -type f -exec mv {} /Volumes/HD1/Images_Old \\;")
			do shell script ("find " & quoted form of (POSIX path of chosenfolder) & " -name " & quoted form of (fnamepartthree) & "_*" & " -type f -exec mv {} " & quoted form of (POSIX path of folderpath) & " \\;")
		end if
		if (length of filename) = 25 and filename contains "_Portrait" then
			set fnamepartone to ((characters 1 through 2 of filename) as Unicode text)
			set fnameparttwo to ((characters 1 through 3 of filename) as Unicode text)
			set fnamepartthree to ((characters 1 through 8 of filename) as Unicode text)
			set fnamepartfour to ((characters 1 through 10 of filename) as Unicode text)
			set folderpath to "HD1:Images:" & fnamepartone & ":" & fnameparttwo & ":"
			do shell script ("find " & quoted form of (POSIX path of folderpath) & " -name " & quoted form of (fnamepartfour) & "_*" & " -type f -exec mv {} /Volumes/HD1/Images_Old \\;")
			do shell script ("find " & quoted form of (POSIX path of chosenfolder) & " -name " & quoted form of (fnamepartfour) & "_*" & " -type f -exec mv {} " & quoted form of (POSIX path of folderpath) & " \\;")
		end if
		if (length of filename) = 26 and filename contains "_Landscape" then
			set fnamepartone to ((characters 1 through 2 of filename) as Unicode text)
			set fnameparttwo to ((characters 1 through 3 of filename) as Unicode text)
			set fnamepartthree to ((characters 1 through 8 of filename) as Unicode text)
			set fnamepartfour to ((characters 1 through 10 of filename) as Unicode text)
			set folderpath to "HD1:Images:" & fnamepartone & ":" & fnameparttwo & ":"
			do shell script ("find " & quoted form of (POSIX path of folderpath) & " -name " & quoted form of (fnamepartfour) & "_*" & " -type f -exec mv {} /Volumes/HD1/Images_Old \\;")
			do shell script ("find " & quoted form of (POSIX path of chosenfolder) & " -name " & quoted form of (fnamepartfour) & "_*" & " -type f -exec mv {} " & quoted form of (POSIX path of folderpath) & " \\;")
		end if
		if (length of filename) = 26 and filename contains "_Portrait" then
			set fnamepartone to ((characters 1 through 2 of filename) as Unicode text)
			set fnameparttwo to ((characters 1 through 3 of filename) as Unicode text)
			set fnamepartthree to ((characters 1 through 8 of filename) as Unicode text)
			set fnamepartfour to ((characters 1 through 10 of filename) as Unicode text)
			set fnamepartfive to ((characters 1 through 11 of filename) as Unicode text)
			set folderpath to "HD1:Images:" & fnamepartone & ":" & fnameparttwo & ":"
			do shell script ("find " & quoted form of (POSIX path of folderpath) & " -name " & quoted form of (fnamepartfive) & "_*" & " -type f -exec mv {} /Volumes/HD1/Images_Old \\;")
			do shell script ("find " & quoted form of (POSIX path of chosenfolder) & " -name " & quoted form of (fnamepartfive) & "_*" & " -type f -exec mv {} " & quoted form of (POSIX path of folderpath) & " \\;")
		end if
		if (length of filename) = 27 and filename contains "_Landscape" then
			set fnamepartone to ((characters 1 through 2 of filename) as Unicode text)
			set fnameparttwo to ((characters 1 through 3 of filename) as Unicode text)
			set fnamepartthree to ((characters 1 through 8 of filename) as Unicode text)
			set fnamepartfour to ((characters 1 through 10 of filename) as Unicode text)
			set fnamepartfive to ((characters 1 through 11 of filename) as Unicode text)
			set folderpath to "HD1:Images:" & fnamepartone & ":" & fnameparttwo & ":"
			do shell script ("find " & quoted form of (POSIX path of folderpath) & " -name " & quoted form of (fnamepartfive) & "_*" & " -type f -exec mv {} /Volumes/HD1/Images_Old \\;")
			do shell script ("find " & quoted form of (POSIX path of chosenfolder) & " -name " & quoted form of (fnamepartfive) & "_*" & " -type f -exec mv {} " & quoted form of (POSIX path of folderpath) & " \\;")
		end if
	end try
end repeat

tell application (path to frontmost application as Unicode text)
	with timeout of 3600 seconds
		display dialog "Beelden zijn verwerkt" buttons {"OK"} default button 1
	end timeout
end tell


Hi,

this is not possible with plain vanilla AppleScript,
you could display a dialog “Processing.” for 2 seconds at the beginning (using the parameter giving up after 2),
and “Done” at the end.

Why do you parse the same files twice? It would be much faster to combine the two repeat loops,
and writing the log with AppleScript’s write command is also much faster then calling a shell script in each iteration

Hi retepp,

In addition to StefanK’s expalanations I would like to add that you might consider to transform your AppleScript into a small and simple AppleScript Studio application, where you could start a progress bar before going into the repeat loops in order to give the user some kind of activity feedback.

Just an idea :slight_smile:

PS:

I haven’t tested the find shell scripts, but this script should do the same thing as yours,
but probably much faster


property logpath : "HD1:Images:"
property oldImages : "/Volumes/HD1/Images_Old"
property logFile : logpath & "log.txt"

set chosenfolder to choose folder with prompt "Kies een map met Leenbakker JPEG's" without invisibles
set chosenPOSIXfolder to quoted form of POSIX path of chosenfolder
tell application "Finder" to set newfiles to files in chosenfolder

write_log from (do shell script "/bin/echo `date +%d-%m-%Y'   '%H:%M:%S`")
repeat with aFile in newfiles
	try
		set {name:filename, creation date:file_creation_date} to info for (aFile as alias)
		tell filename to set {fnamepartone, fnameparttwo} to {text 1 thru 2, text 1 thru 3}
		set fnamepath to quoted form of (text 1 thru ((offset of "_" in filename) - 1) of filename)
		set folderpath to logpath & fnamepartone & ":" & fnameparttwo & ":"
		set folderPOSIXpath to quoted form of POSIX path of folderpath
		write_log from ("Name: " & filename & " Creation Date: " & file_creation_date)
		try
			set folderalias to folderpath as alias
		on error
			do shell script "/bin/mkdir -p " & folderPOSIXpath
		end try
		do shell script ("/usr/bin/find " & folderPOSIXpath & " -name " & fnamepath & "_*" & " -type f -exec mv {} " & quoted form of oldImages & " \\;")
		do shell script ("/usr/bin/find " & chosenPOSIXfolder & " -name " & fnamepath & "_*" & " -type f -exec mv {} " & folderPOSIXpath & " \\;")
	end try
end repeat


tell application (path to frontmost application as Unicode text)
	display dialog "Beelden zijn verwerkt" buttons {"OK"} default button 1 giving up after 3600
end tell

on write_log from theMessage
	try
		set the logStream to open for access file logFile with write permission
		set logFileEof to get eof of the logStream
		write theMessage & return to logStream starting at eof as «class utf8»
		close access logStream
		return true
	on error
		try
			close access file logFile
		end try
		return false
	end try
end write_log

Hi Stefan,

I tried your script

There are two problems:

  1. The Write_Log only writes the first file of : 60151152-1_Landscape_L.jpg, 60151152-1_Landscape_M.jpg, 60151152-1_Landscape_L.jpg

  2. It only moves : 60151152-1_Landscape_L.jpg, 60151152-1_Landscape_M.jpg, 60151152-1_Landscape_L.jpg
    The other files:
    50100430-11_Landscape_S.jpg
    50100430-11_Landscape_L.jpg
    50100430-11_Landscape_M.jpg
    60100005_Portrait_L.jpg
    60100005_Portrait_M.jpg
    60100005_Portrait_S.jpg
    60100092-1_Portrait_L.jpg
    60100092-1_Portrait_M.jpg
    60100092-1_Portrait_S.jpg
    Remain in the choosenfolder

Any idea?

Thanks in advance,
Peter

Stefan,
forget the previous reply, I made a mistake by messing up your script.

Peter

Hi Stefan,

I’ve tested your script and it is LIGHTNING fast!!!
Thanks a lot

I had to build in an additional repaet with… because only the first of the three files appeared in the log.

I implemented the ‘Progress Bar’ to give people some idea that someting is happening because we often need to proces a couple of hundred files.
Is it possible to udate the progress bar by the number of files witch are being processed in the first and second part of the script?


property logpath : "HD1:Images:"
property oldImages : "/Volumes/HD1/Images_Old"
property logFile : logpath & "log.txt"

set chosenfolder to choose folder with prompt "Choose an Inputfolder" without invisibles
set chosenPOSIXfolder to quoted form of POSIX path of chosenfolder
tell application "Finder" to set newfiles to files in chosenfolder

set ProgressBar to load script alias (((path to scripts folder) as text) & "Lib:BP Progress Bar Controller.scpt")
tell ProgressBar
	initialize("Move JPEG Phase One")
	barberPole(true)
	setStatusTop to "Collect File Info for Log"
	setStatusBottom to "Only a moment..."
end tell

Write_Log from (do shell script "/bin/echo `date +%d-%m-%Y'   '%H:%M:%S`")
repeat with aFile in newfiles
	set {name:filename, creation date:file_creation_date} to info for (aFile as alias)
	Write_Log from ("Name: " & filename & " Creation Date: " & file_creation_date)
end repeat

tell ProgressBar to quit

set ProgressBar to load script alias (((path to scripts folder) as text) & "Lib:BP Progress Bar Controller.scpt")
tell ProgressBar
	initialize("Move JPEG Phase 2")
	barberPole(true)
	setStatusTop to "Moving the JPEG's."
	setStatusBottom to "Only a moment..."
end tell

repeat with aFile in newfiles
	try
		set filename to name of aFile
		tell filename to set {fnamepartone, fnameparttwo} to {text 1 thru 2, text 1 thru 3}
		set fnamepath to quoted form of (text 1 thru ((offset of "_" in filename) - 1) of filename)
		set folderpath to logpath & fnamepartone & ":" & fnameparttwo & ":"
		set folderPOSIXpath to quoted form of POSIX path of folderpath
		--Write_Log from ("Name: " & filename & " Creation Date: " & file_creation_date)
		try
			set folderalias to folderpath as alias
		on error
			do shell script "/bin/mkdir -p " & folderPOSIXpath
		end try
		do shell script ("/usr/bin/find " & folderPOSIXpath & " -name " & fnamepath & "_*" & " -type f -exec mv {} " & quoted form of oldImages & " \\;")
		do shell script ("/usr/bin/find " & chosenPOSIXfolder & " -name " & fnamepath & "_*" & " -type f -exec mv {} " & folderPOSIXpath & " \\;")
	end try
end repeat

tell ProgressBar to quit

tell application (path to frontmost application as Unicode text)
	display dialog "JPEG's are moved" buttons {"OK"} default button 1 giving up after 36000
end tell

on Write_Log from theMessage
	try
		set the logStream to open for access file logFile with write permission
		set logFileEof to get eof of the logStream
		write theMessage & return to logStream starting at eof as «class utf8»
		close access logStream
		return true
	on error
		try
			close access file logFile
		end try
		return false
	end try
end Write_Log

Peter,

I curious how your progress bar controller script works. Can you provide an example?

Thanks
Mark

Hi Mark,

Download the BP Progress Bar from this forum. (This also includes some examples)
http://scriptbuilders.net/files/bpprogressbar1.0.html
Move the files to the Scripts/Lib Folder and call it from your script - see previous post

Peter

Thanks Peter. This is awesome, nice of Bruce to share.

I’m actually going to place it the resources folder of an application bundle so it moves with the script without relying on the user to have it, then call it with the “path to resource” command. Works nice with Adam’s demo saved as an app bundle. Now to move it into one of my actual scripts.

Thanks Again,
Mark