Slow Performance after running script repeatadly

Hi All,

I whipped up a script to help me deliver files to a client that I have a really large job for. The script works fine and does everything I need but after I run it over and over, I run it each time I deliver a finish image, the computer seems to get bogged down. The machine I’m running the script from is not being used for anything else aside from file sharing but if I do try to do something like open system prefs it takes forever as well as just basic finder use. Does anyone see anything in this script that could cause performance issues?

I have a Photoshop Action that save off various files sizes to a folder and sub folders for each image.

What the script does:

Copies that folder to a new location.
Renames the folder to the image name
Renames a file
Compresses, renames and uploads the folder
Deletes the original files
Changes the tag on the Photoshop file.

Compter specs:
Mac Pro 1,1 running 10.7.5, 14gb RAM, Radeon 4870

Thanks for any insight,
Mark

--// Retain default text item delimiters
set AppleScript's text item delimiters to ""
set ASTID to AppleScript's text item delimiters

--// Variables

global currentFilename
set currentFilename to ""

global advanceAutoFolder
set advanceAutoFolder to ""

global autoZoneFolder
set autoZoneFolder to ""

global daycoFolder
set daycoFolder to ""

global talkingPicturesFolder
set talkingPicturesFolder to ""

set theServerAddress to "omitted"
set theUserName to "omitted"
set thePassword to "omitted"


tell application "Finder"
	set sourceFolder to folder "Work HD:Processed Images:Dayco" as alias
	set destinationFolder to folder "Work HD:Work Storage:Jobs:1709-02 Dayco:Output:Finals" as alias
	
	set advanceAutoFolder to folder "Work HD:Processed Images:Dayco:Advance" as alias
	set autoZoneFolder to folder "Work HD:Processed Images:Dayco:AutoZone" as alias
	set daycoFolder to folder "Work HD:Processed Images:Dayco:Dayco" as alias
	set talkingPicturesFolder to folder "Work HD:Processed Images:Dayco:Talking_Pictures" as alias
end tell

--// Get file name & copy the folder to Finals
tell application "Finder"
	-- Check that folder is not empty or has more then one file in the Advance folder
	set fileCount to (count the files in the folder advanceAutoFolder)
	if (fileCount = 1) then
		-- Copy the name of the tif file in the Advance folder
		repeat with i in (get files of folder ((advanceAutoFolder) as string) whose name ends with ".tif")
			try
				set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "."}
				set {name:fileName, name extension:nameExtension} to i
				set currentFilename to text 1 thru ((get offset of "." & nameExtension in fileName) - 1) of fileName
				set AppleScript's text item delimiters to ASTID
			on error
				tell application "Finder"
					display dialog "No file in " & advanceAutoFolder buttons {"OK"} giving up after 5 default button 1 with icon caution
				end tell
			end try
		end repeat
		
	else if (fileCount = 0) then
		tell application "Finder"
			display dialog "There are no files to process." buttons {"OK"} giving up after 5 default button 1 with icon caution
			return
		end tell
	else if (fileCount > 1) then
		tell application "Finder"
			display dialog "There are too many files to process. Confirm only one image per folder." buttons {"OK"} giving up after 5 default button 1 with icon caution
			return
		end tell
	end if
	
	-- Close the sourceFolder before copying
	tell application "Finder"
		activate
		select sourceFolder
	end tell
	tell application "System Events"
		tell application process "Finder"
			key code 123 -- Left Arrow - CLOSE (works without any other keys)
		end tell
	end tell
	delay 1
	
	-- Copy the source folder to Finals
	duplicate sourceFolder to destinationFolder with replacing
	
	--// Set folder variables to the copied folder
	set copiedFolder to folder "Work HD:Work Storage:Jobs:1709-02 Dayco:Output:Finals:Dayco" as alias
	set newAdvanceAutoFolder to folder "Work HD:Work Storage:Jobs:1709-02 Dayco:Output:Finals:Dayco:Advance" as alias
	
	-- Add "164_" to the filename of the image in the "Advance" folder
	repeat with i in (get files of folder ((newAdvanceAutoFolder) as string) whose name ends with ".tif")
		try
			set textitems to text items of (get name of i)
			set name of contents of i to "164_" & items of textitems as Unicode text
		on error errmsg
			tell application "Finder"
				display dialog "Error: " & errmsg buttons {"OK"} giving up after 5 default button 1 with icon caution
			end tell
		end try
	end repeat
	
	-- Rename the copied folder to the file name
	set name of copiedFolder to currentFilename
	
	-- Update the reference to the copiedFolder after renaming
	set copiedFolder to folder ("Work HD:Work Storage:Jobs:1709-02 Dayco:Output:Finals:" & currentFilename) as alias
	
end tell

--// Compress the folder for client area
with timeout of 1000000 seconds
	try
		tell application "Finder"
			-- Destination of the zipped file
			set destFold to quoted form of POSIX path of ¬
				(destinationFolder as alias)
			
			-- Source for the file to be zipped
			set sourceFile to quoted form of POSIX path of (copiedFolder as alias)
			
			-- Set the zip file location and name
			set zipFile to (destFold as Unicode text) & currentFilename & ".zip"
			
			-- Zip the file
			do shell script "ditto -ck --keepParent " & sourceFile & space & zipFile
			
			-- Get reference to the new zipped file
			set newZipFile to "Work HD:Work Storage:Jobs:1709-02 Dayco:Output:Finals:" & currentFilename & ".zip" as alias
			
			-- Rename the zip file for client area. Add "hr_" to beginning
			set name of newZipFile to "hr_" & currentFilename & ".zip"
			
			-- Set the path to the matching PSD file to label it Complete
			set photoshopFile to file ("Work HD:Work Storage:Jobs:1709-02 Dayco:Output:PSD:" & currentFilename & ".psd") as alias
		end tell
	on error errmsg
		--should anything go wrong let the user know
		display dialog errmsg
	end try
end timeout

--// Select upload loacation based on the ending of the file name
if ((newZipFile as Unicode text) does not end with "FRO.zip") then
	set theDirectory to "/ImageFolio42_files/client_area/Dayco/Job_1709-02/Secondary/"
else
	set theDirectory to "/ImageFolio42_files/client_area/Dayco/Job_1709-02/Primary/"
end if

--// Upload newZipFile via transmit
tell application "Transmit"
	set theDocument to make new document with properties {name:theServerAddress}
	tell theDocument
		tell «class aSes»
			«event SeSncONT» given «class sRVR»:theServerAddress, «class uNAM»:theUserName, «class uPAS»:thePassword, «class iPAT»:theDirectory
			«event SeSnuPLD» given «class uFLE»:newZipFile, «class rsMD»:«constant rsMDoTRN»
		end tell
		close
	end tell
end tell

--// Label file and folder and remove files
tell application "Finder"
	-- Label the folder gray
	set label index of copiedFolder to 7
	
	-- Label the photoshop file red
	set label index of photoshopFile to 2
	
	-- Move the uploaded file to the trash
	move newZipFile to the trash
	
	-- Open the sourceFolder on completion
	select sourceFolder
	tell application "System Events"
		tell application process "Finder"
			key code 124 -- Right Arrow - OPEN (works without any other keys)
		end tell
	end tell
	
	-- Empty the folders
	move files of folder ((advanceAutoFolder) as string) to trash
	move files of folder ((autoZoneFolder) as string) to trash
	move files of folder ((daycoFolder) as string) to trash
	move files of folder ((talkingPicturesFolder) as string) to trash
end tell

--0 -> No Label
--1 -> Orange Label
--2 -> Red Label
--3 -> Yellow Label
--4 -> Blue Label
--5 -> Purple Label
--6 -> Green Label
--7 -> Gray Label

Hi.

I’m not sure why the script’s slowing down over time, but I’ve fooled around with it a bit to ensure that the variables are non-persistent (ie. that their values aren’t saved back into the script file at the end), to remove the nesting of ‘tell’ statements to applications, and to remove some of the superfluities in the coding. I haven’t tested the complete result as I don’t have your folder set-up or “Transmit”, so I don’t know if I’ve introduced any bugs or if it behaves any better than the original. You should test yourself on something harmless before using it in earnest!

main()

-- All the action in a handler so that the variables are all local and therefore non-persistent.
on main()
	--// Variables
	
	set theServerAddress to "omitted"
	set theUserName to "omitted"
	set thePassword to "omitted"
	
	set sourceFolder to "Work HD:Processed Images:Dayco" as alias
	set destinationFolder to "Work HD:Work Storage:Jobs:1709-02 Dayco:Output:Finals" as alias
	
	set advanceAutoFolder to "Work HD:Processed Images:Dayco:Advance" as alias
	set autoZoneFolder to "Work HD:Processed Images:Dayco:AutoZone" as alias
	set daycoFolder to "Work HD:Processed Images:Dayco:Dayco" as alias
	set talkingPicturesFolder to "Work HD:Processed Images:Dayco:Talking_Pictures" as alias
	
	--// Get file name & copy the folder to Finals
	tell application "Finder"
		activate -- So that the dialogs it displays appear in front of anything else and the System Events key codes reach it.
		
		-- Check that folder is not empty or has more then one file in the Advance folder
		set fileCount to (count the files in the advanceAutoFolder)
		if (fileCount = 1) then
			-- Copy the name of the tif file in the Advance folder
			set fileName to name of file 1 of advanceAutoFolder
			if (fileName ends with ".tif") then
				set currentFilename to text 1 thru -5 of fileName
			else
				display dialog "No .tif file in " & advanceAutoFolder buttons {"OK"} giving up after 5 default button 1 with icon caution
				return
			end if
		else if (fileCount = 0) then
			display dialog "There are no files to process." buttons {"OK"} giving up after 5 default button 1 with icon caution
			return
		else if (fileCount > 1) then
			display dialog "There are too many files to process. Confirm only one image per folder." buttons {"OK"} giving up after 5 default button 1 with icon caution
			return
		end if
		
		-- Close the sourceFolder before copying (presumably meaning unexpand the view of its contents in the list-view window of another folder).
		select sourceFolder
	end tell
	tell application "System Events" to key code 123
	
	tell application "Finder"
		-- Copy the source folder to Finals and set variables to the copied folder and the "Advance" folder inside it.
		set copiedFolder to (duplicate sourceFolder to destinationFolder with replacing) as alias
		set newAdvanceAutoFolder to (folder "Advance" of copiedFolder) as alias
		
		-- Add "164_" to the filename (which we've already extracted) of the image in the "Advance" folder
		try
			set name of first file of newAdvanceAutoFolder to "164_" & fileName
		on error errmsg
			display dialog "Error: " & errmsg buttons {"OK"} giving up after 5 default button 1 with icon caution
			return
		end try
		
		-- Rename the copied folder to the file name
		set name of copiedFolder to currentFilename
		
		-- SInce copiedFolder is an alias, there's no need to update it after the renaming
		
	end tell
	
	--// Compress the folder for client area
	with timeout of 1000000 seconds
		try
			
			-- Destination of the zipped file
			set destFold to quoted form of POSIX path of destinationFolder
			
			-- Source for the file to be zipped
			set sourceFile to quoted form of POSIX path of copiedFolder
			
			-- Set the zip file location and name
			set zipFile to destFold & currentFilename & ".zip"
			
			-- Zip the file
			do shell script "ditto -ck --keepParent " & sourceFile & space & zipFile
			
			-- Get reference to the new zipped file
			set newZipFile to zipFile as POSIX file as alias
			
			-- Rename the zip file for client area. Add "hr_" to beginning
			tell application "Finder" to set name of newZipFile to "hr_" & currentFilename & ".zip"
			
			-- Set the path to the matching PSD file to label it Complete
			set photoshopFile to ("Work HD:Work Storage:Jobs:1709-02 Dayco:Output:PSD:" & currentFilename & ".psd") as alias
		on error errmsg
			--should anything go wrong let the user know
			tell application "Finder" to display dialog errmsg
		end try
	end timeout
	
	--// Select upload loacation based on the ending of the file name
	if ((newZipFile as Unicode text) does not end with "FRO.zip") then
		set theDirectory to "/ImageFolio42_files/client_area/Dayco/Job_1709-02/Secondary/"
	else
		set theDirectory to "/ImageFolio42_files/client_area/Dayco/Job_1709-02/Primary/"
	end if
	
	--// Upload newZipFile via transmit
	tell application "Transmit"
		set theDocument to make new document with properties {name:theServerAddress}
		tell theDocument
			tell «class aSes»
				«event SeSncONT» given «class sRVR»:theServerAddress, «class uNAM»:theUserName, «class uPAS»:thePassword, «class iPAT»:theDirectory
				«event SeSnuPLD» given «class uFLE»:newZipFile, «class rsMD»:«constant rsMDoTRN»
			end tell
			close
		end tell
	end tell
	
	--// Label file and folder and remove files
	tell application "Finder"
		-- Label the folder gray
		set label index of copiedFolder to 7
		
		-- Label the photoshop file red
		set label index of photoshopFile to 2
		
		-- Move the uploaded file to the trash
		move newZipFile to the trash
		
		-- Open the sourceFolder on completion (ie. expand the view of its contents in the list-view window of another folder)
		select sourceFolder
	end tell
	tell application "System Events" to key code 124 -- Right Arrow - OPEN (works without any other keys)
	
	tell application "Finder"
		-- Empty the folders
		move files of advanceAutoFolder to trash
		move files of autoZoneFolder to trash
		move files of daycoFolder to trash
		move files of talkingPicturesFolder to trash
	end tell
end main
--0 -> No Label
--1 -> Orange Label
--2 -> Red Label
--3 -> Yellow Label
--4 -> Blue Label
--5 -> Purple Label
--6 -> Green Label
--7 -> Gray Label

To make the script easier to maintain I would make small changes at the beginning:

set destinationFolder to "Work HD:Work Storage:Jobs:1709-02 Dayco:Output:Finals" as alias
set sourceFolder to "Work HD:Processed Images:Dayco:" # Keep a string but add the ending colon
#Building the 4 other aliases is "cleaner"
set advanceAutoFolder to (sourceFolder & "Advance") as alias
set autoZoneFolder to (sourceFolder & "AutoZone") as alias
set daycoFolder to (sourceFolder & "Dayco") as alias
set talkingPicturesFolder to (sourceFolder & "Talking_Pictures") as alias
# Coerce to alias here
set sourceFolder to sourceFolder as alias

Yvan KOENIG running High Sierra 10.13.2 in French (VALLAURIS, France) vendredi 15 décembre 2017 15:34:14

Thanks for looking into that but I think I finally tracked down the real issue. I use softraid to make a RAID mirror for my work volume and had added a third slice to it that is on firewire 800 while the other drives are internal eSATA. I decided to turn that drive off and the performance issue stopped. Then today I fired that slice back up and now softraid reports that slice is failing with excessive bad blocks.

Thanks for the input. I’ll incorporate that into the script.

Regards,
Mark