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