Design project workflow.

My first time automating a workflow in AccpleScript and I’m about 95% of the way there, and I think I’ve painted myself into a corner, as it were. The current workflow here involves moving vendor-delivered files into a new folder, renamed, relinked, and jpg previews of the main files are created. Normally this involves a lot of manual work and can be time consuming on large jobs. I’ve managed to simplify the manual stuff thus far (I’m not worried about automating the previews at this point), and I’m hoping for help on the following things:

A) (edit) Is there a way for me to make parts of the script skippable without terminating the entire script after it designates the main PDF (e.g., there are no “_ART” files, so move on to the next step)?
B) (edit) Is it possible to start at the projectFolder level when the user needs to select files? (DONE!)
C) (new) For each step where files are renamed (starting at the _ART rename step), how can I export the list of filenames changed, listing the before-and-after to a text file saved to the desktop, so that if files need to be relinked in InDesign or Illustrator, it will be easier for the user to reference the new file names?

I know this is a pretty verbose script, but I’m taking things a baby step at a time. Any help would be appreciated. Thanks!

—UPDATE: trimmed it out a bit so it’s a single Finder tell and updated the default folder location (thanks Marc!)

set text item delimiters to "."
set text item delimiters to "."
tell application "Finder"
	
	--SETUP
	--get Job code
	display dialog "Enter Job Code:" default answer "JobCode"
	set projCode to text returned of result
	--designate project folder
	set projectFolder to choose folder with prompt "Select project folder"
	
	--ZIP FONTS & RENAME
	set zipSuffix to "_TYPEFACES"
	--pick font folder
	set inputFolder to choose folder with prompt "Select font folder to be zipped"
	tell current application
		set qpp to quoted form of POSIX path of inputFolder
		do shell script "cd $(dirname " & qpp & ")
    zip -r  \"$(basename " & projCode & zipSuffix & ").zip\" \"$(basename " & qpp & ")\""
	end tell
	--delete original files
	delete inputFolder
	
	--CREATE NEW PROJECT FOLDERS AND SORT FILES
	make new folder at projectFolder with properties {name:"HIRES"}
	--set path to move to HIRES folder
	set hiFiles to (projectFolder as string) & "HIRES"
	
	-- move all files to HIRES
	set targetFiles to get every item of (entire contents of projectFolder) whose kind ≠ "Folder"
	--more files into HIRES
	move targetFiles to hiFiles
	--remove extraneous folders
	delete (every folder of projectFolder whose name is not "HIRES")
	--create previews folder
	make new folder at projectFolder with properties {name:"PREVIEWS"}
	
	--DESIGNATE MAIN MECHANICAL
	--pick the file
	set mainMech to (choose file default location projectFolder with prompt "Select primary mechanical file:")
	--get the filename to save the extension
	set mainFNCount to text items of (get name of mainMech)
	--pull original filename extension
	if number of mainFNCount is 1 then
		set mainExt to ""
	else
		set mainExt to "." & item -1 of mainFNCount
	end if
	--rename file
	set the name of mainMech to projCode & mainExt as string
	
	--DESIGNATE MAIN PDF
	--pick the file
	set mainPDF to (choose file default location projectFolder with prompt "Select primary PDF file:")
	--get the filename to save the extension
	set mainFNCount to text items of (get name of mainPDF)
	--pull original filename extension
	if number of mainFNCount is 1 then
		set mainExt to ""
	else
		set mainExt to "." & item -1 of mainFNCount
	end if
	--rename file
	set the name of mainPDF to projCode & "_PDF01" & mainExt as string
	
	--RENAME ALL _ART FILES IN SEQUENCE
	set all_files to every item of (choose file default location projectFolder with prompt "Select all _ART files:" with multiple selections allowed) as list
	
	--add in the support filename suffix
	set artSuffix to "_ART"
	
	--start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file.
	--the 'index' number is required for the sequential renaming of files
	repeat with index from 1 to the count of all_files
		--using our index, we select the appropriate file from our list
		set this_file to item index of all_files
		set file_name_count to text items of (get name of this_file)
		
		--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later
		if index is less than 10 then
			set index_prefix to "0"
		else
			set index_prefix to ""
		end if
		
		--lets check if the current file from our list (based on index-number) has even any file-extension
		if number of file_name_count is 1 then
			
			--file_name-count = 1 means, we extracted only 1 text-string from the full file name. So there is no file-extension present.
			set file_extension to ""
		else
			--re-add the original file-extension after changing the name of the file
			set file_extension to "." & item -1 of file_name_count
		end if
		
		--rename file, add the sequential number from 'index' and add the file-extension to it
		set the name of this_file to projCode & artSuffix & index_prefix & index & file_extension as string
	end repeat
	display notification "File Rename Complete " & index & " files with '" & projCode & "' for you."
	
	--RENAME ALL _BIT FILES IN SEQUENCE
	set all_files to every item of (choose file default location projectFolder with prompt "Select all _BIT files:" with multiple selections allowed) as list
	
	--add in the support filename suffix
	set bitSuffix to "_BIT"
	
	--start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file.
	--the 'index' number is required for the sequential renaming of files
	repeat with index from 1 to the count of all_files
		--using our index, we select the appropriate file from our list
		set this_file to item index of all_files
		set file_name_count to text items of (get name of this_file)
		
		--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later
		if index is less than 10 then
			set index_prefix to "0"
		else
			set index_prefix to ""
		end if
		
		--lets check if the current file from our list (based on index-number) has even any file-extension
		if number of file_name_count is 1 then
			
			--file_name-count = 1 means, we extracted only 1 text-string from the full file name. So there is no file-extension present.
			set file_extension to ""
		else
			--re-add the original file-extension after changing the name of the file
			set file_extension to "." & item -1 of file_name_count
		end if
		
		--rename file, add the sequential number from 'index' and add the file-extension to it
		set the name of this_file to projCode & bitSuffix & index_prefix & index & file_extension as string
	end repeat
	display notification "File Rename Complete " & index & " files with '" & projCode & "' for you."
	
	--RENAME ALL _LYRD FILES IN SEQUENCE
	set all_files to every item of (choose file default location projectFolder with prompt "Select all _LYRD files:" with multiple selections allowed) as list
	
	--add in the support filename suffix
	set lyrdSuffix to "_LYRD"
	
	--start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file.
	--the 'index' number is required for the sequential renaming of files
	repeat with index from 1 to the count of all_files
		--using our index, we select the appropriate file from our list
		set this_file to item index of all_files
		set file_name_count to text items of (get name of this_file)
		
		--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later
		if index is less than 10 then
			set index_prefix to "0"
		else
			set index_prefix to ""
		end if
		
		--lets check if the current file from our list (based on index-number) has even any file-extension
		if number of file_name_count is 1 then
			
			--file_name-count = 1 means, we extracted only 1 text-string from the full file name. So there is no file-extension present.
			set file_extension to ""
		else
			--re-add the original file-extension after changing the name of the file
			set file_extension to "." & item -1 of file_name_count
		end if
		
		--rename file, add the sequential number from 'index' and add the file-extension to it
		set the name of this_file to projCode & lyrdSuffix & index_prefix & index & file_extension as string
	end repeat
	display notification "File Rename Complete " & index & " files with '" & projCode & "' for you."
	
	--RENAME ALL _IL FILES IN SEQUENCE
	set all_files to every item of (choose file default location projectFolder with prompt "Select all _IL files:" with multiple selections allowed) as list
	
	--add in the support filename suffix
	set ilSuffix to "_IL"
	
	--start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file.
	--the 'index' number is required for the sequential renaming of files
	repeat with index from 1 to the count of all_files
		--using our index, we select the appropriate file from our list
		set this_file to item index of all_files
		set file_name_count to text items of (get name of this_file)
		
		--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later
		if index is less than 10 then
			set index_prefix to "0"
		else
			set index_prefix to ""
		end if
		
		--lets check if the current file from our list (based on index-number) has even any file-extension
		if number of file_name_count is 1 then
			
			--file_name-count = 1 means, we extracted only 1 text-string from the full file name. So there is no file-extension present.
			set file_extension to ""
		else
			--re-add the original file-extension after changing the name of the file
			set file_extension to "." & item -1 of file_name_count
		end if
		
		--rename file, add the sequential number from 'index' and add the file-extension to it
		set the name of this_file to projCode & ilSuffix & index_prefix & index & file_extension as string
	end repeat
	display notification "File Rename Complete " & index & " files with '" & projCode & "' for you."
	
end tell

Hi. Welcome to the forum. Request B is easily resolved through a choose file/folder option; e.g.,

choose file default location projectFolder

It’s a common AppleScript newbie error to send most commands to Finder, but calls to standard additions”like choose file/folder or do shell script”should not be so directed, and you nested most everything within another Finder block, which could cause errors.

Oh! Duh…I should have guessed that, thanks!

You’re right that I’m just kinda ham-handing this, I’m used to creating functions (former ActionScript guy…yeah, I know, I still flinch at that) so moving to the “other” AS has been a transition. Ideally, I’d just make a single function, or handler, to do the rename/resequence and pass through the filename extension with each step.

Are A and C still feasible?

EDIT: Updated with you help, thanks!

Hnnnggg. Getting closer on C. Extracted out a part of the script to test, but I’m missing something. I keep getting a blank text file. If I can get this to work, I’ll repeat it to get the new file names after the rename/sequence. However, once this works, how do I write it so that the before-and-after names are correct and in sequence in the text file (e.g., A => 1, B => 2)?

tell application "Finder"
	set projectFolder to choose folder with prompt "Select project folder"
	set all_files to every item of (choose file default location projectFolder with prompt "Select all _ART files:" with multiple selections allowed) as list
	set beforeList to all_files as string
	set listOutput to ((path to desktop as text) & "test.txt")
	try
		set beforeList to open for access file listOutput with write permission
		write beforeList to listOutput as string
		close access listOutput
	on error
		try
			close access file listOutput
		end try
	end try
end tell

Hi. I’m not sure exactly what you’re asking and to what extent I can help, considering this topic appears to be of a commercial nature. You can avoid opening and closing for access, unless you’re changing the end of file position. Perhaps this will get you closer to solving your problem.

set text item delimiters to return
set projectFolder to choose folder with prompt "Select project folder"
set _ART to (choose file default location projectFolder with prompt "Select all ART files:" with multiple selections allowed) --already a list

tell application "Finder" to set writeTarget to ((make file) as alias) --finder needed for make

write (_ART as text) to writeTarget

I’m freelancing for a media company and I get a deluge of projects to manually sort, rename, and relink to InDesign or Illustrator (if necessary). Usually I screenshot the list of files to be renamed when using an app called NameChanger (really nifty tool). So when I have to relink files to a document, I’ll know that for example, the “originalfile.tif” is now “newfile_art01.tif” and I can relink it accordingly. But if instead I can just reference a text file, won’t need to stop and take a screenshot. I hope that clarifies things a bit more.

I do appreciate your assistance, it’s been very helpful!

Finally!

After much more tinkering I managed to simplify the script into a single handler to sequence through my file types. This works perfectly (with the caveat that the project folder does not contain spaces or it errors out when zipping fonts), and does the heavy lifting for me. My only wish list items are to exclude the file paths from the text file outputs and make this a drag-and-drop app where I can just drag the project folder to process. Thanks to everyone who helped!

--SETUP
set text item delimiters to "."
tell application "Finder"
	
	--GET JOB CODE
	display dialog "ENTER JOB CODE:" default answer "JobCode"
	set projCode to text returned of result
	--designate project folder (may change to "this folder" as a drag-and-drop later)
	set projectFolder to choose folder with prompt "SELECT PROJECT FOLDER"
	
	--ZIP FONTS & RENAME
	set zipSuffix to "_TYPEFACES"
	--pick font folder
	set inputFolder to choose folder default location projectFolder with prompt "SELECT FONT FOLDER"
	tell current application
		set qpp to quoted form of POSIX path of inputFolder
		do shell script "cd $(dirname " & qpp & ")
    zip -r  \"$(basename " & projCode & zipSuffix & ").zip\" \"$(basename " & qpp & ")\""
	end tell
	--delete original files
	delete inputFolder
	
	--CREATE NEW PROJECT FOLDERS AND SORT FILES
	make new folder at projectFolder with properties {name:"HIRES"}
	--set path to move to HIRES folder
	set hiFiles to (projectFolder as string) & "HIRES"
	--designate files to move into HIRES
	set targetFiles to get every item of (entire contents of projectFolder) whose kind ≠ "Folder"
	--move files into HIRES
	move targetFiles to hiFiles
	--remove extraneous folders
	delete (every folder of projectFolder whose name is not "HIRES")
	--create preview folder
	make new folder at projectFolder with properties {name:"PREVIEWS"}
	
	--DESIGNATE MAIN MECHANICAL
	set mainMech to (choose file default location projectFolder with prompt "SELECT MAIN MECHANICAL FILE")
	--get the filename to save the extension
	set mainFNCount to text items of (get name of mainMech)
	--pull original filename extension
	if number of mainFNCount is 1 then
		set mainExt to ""
	else
		set mainExt to "." & item -1 of mainFNCount
	end if
	--rename file
	set the name of mainMech to projCode & mainExt as string
	
	--DESIGNATE MAIN PDF
	set mainPDF to (choose file default location projectFolder with prompt "SELECT MAIN PDF FILE")
	--get the filename to save the extension
	set mainFNCount to text items of (get name of mainPDF)
	--pull original filename extension
	if number of mainFNCount is 1 then
		set mainExt to ""
	else
		set mainExt to "." & item -1 of mainFNCount
	end if
	--rename file
	set the name of mainPDF to projCode & "_PDF01" & mainExt as string
	
end tell

--RENAME/SEQUENCE SUPPORT FILES
--launch
set seqCount to 1
initSeq(projCode, seqCount)

--check current initSeq count
on initSeq(projCode, seqCount)
	--default sequence order
	if seqCount = 1 then
		seqART(projCode, seqCount)
	else if seqCount = 2 then
		seqBIT(projCode, seqCount)
	else if seqCount = 3 then
		seqIL(projCode, seqCount)
	else if seqCount = 4 then
		seqLYRD(projCode, seqCount)
		--reset count for next project
		set seqCount to 1
	end if
end initSeq

--sequence through different support files
--sequence _ART
on seqART(projCode, seqCount)
	set fileSuffix to "_ART"
	display dialog "Rename/Sequence _ART?" buttons {"Yes", "Skip", "Cancel"} default button 1 with icon caution
	set x to button returned of result
	if x is "Yes" then
		seqFILES(fileSuffix, projCode, seqCount)
	else if x is "Skip" then
		seqBIT(projCode, seqCount)
	else if x is "Cancel" then
		cancel
	end if
end seqART

--sequence _BIT
on seqBIT(projCode, seqCount)
	set fileSuffix to "_BIT"
	display dialog "Rename/Sequence _BIT?" buttons {"Yes", "Skip", "Cancel"} default button 1 with icon caution
	set x to button returned of result
	if x is "Yes" then
		seqFILES(fileSuffix, projCode, seqCount)
	else if x is "Skip" then
		seqIL(projCode, seqCount)
	else if x is "Cancel" then
		cancel
	end if
end seqBIT

--sequence _IL
on seqIL(projCode, seqCount)
	set fileSuffix to "_IL"
	display dialog "Rename/Sequence _IL?" buttons {"Yes", "Skip", "Cancel"} default button 1 with icon caution
	set x to button returned of result
	if x is "Yes" then
		seqFILES(fileSuffix, projCode, seqCount)
	else if x is "Skip" then
		seqLYRD(projCode, seqCount)
	else if x is "Cancel" then
		cancel
	end if
end seqIL

--sequence _LYRD
on seqLYRD(projCode, seqCount)
	set fileSuffix to "_LYRD"
	display dialog "Rename/Sequence _LYRD?" buttons {"Yes", "Skip", "Cancel"} default button 1 with icon caution
	set x to button returned of result
	if x is "Yes" then
		seqFILES(fileSuffix, projCode, seqCount)
	else if x is "Skip" then
		stop
	else if x is "Cancel" then
		cancel
	end if
end seqLYRD

--may need to pass projectFolder as well
on seqFILES(fileSuffix, projCode, seqCount)
	--RENAME ALL SUPPORT FILES IN SEQUENCE
	tell application "Finder"
		--pick files
		set all_files to every item of (choose file with prompt "SELECT " & fileSuffix & " FILES:" with multiple selections allowed) as list
		
		--write before list to desktop
		tell application "Finder" to set writeTarget to ((make new file with properties {name:fileSuffix & "_BEFORE"}) as alias) --create BEFORE text file on desktop
		set _BEFORE to all_files
		write (_BEFORE as text) to writeTarget
		
		--start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file.
		--the 'index' number is required for the sequential renaming of files
		repeat with index from 1 to the count of all_files
			--using our index, we select the appropriate file from our list
			set this_file to item index of all_files
			set file_name_count to text items of (get name of this_file)
			
			--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later
			if index is less than 10 then
				set index_prefix to "0"
			else
				set index_prefix to ""
			end if
			
			--lets check if the current file from our list (based on index-number) has even any file-extension
			if number of file_name_count is 1 then
				
				--file_name-count = 1 means, we extracted only 1 text-string from the full file name. So there is no file-extension present.
				set file_extension to ""
			else
				--re-add the original file-extension after changing the name of the file
				set file_extension to "." & item -1 of file_name_count
			end if
			
			--rename file, add the sequential number from 'index' and add the file-extension to it
			set the name of this_file to projCode & fileSuffix & index_prefix & index & file_extension as string
		end repeat
		
		--write after list to desktop
		tell application "Finder" to set writeTarget to ((make new file with properties {name:fileSuffix & "_AFTER"}) as alias) --create BEFORE text file on desktop
		set _AFTER to all_files
		write (_AFTER as text) to writeTarget
		
		display notification "File Rename Complete " & index & " files with '" & projCode & "' for you."
	end tell
	
	--add in increment to seqCount and restart sequence
	set seqCount to seqCount + 1
	initSeq(projCode, seqCount)
	
end seqFILES