Combine separate before/after lists into a single arrayed list?

Hey folks,

Part of my current script deals with renaming files in a folder, and spits out two text files, one before and another after the rename. I’m wondering how would I combine those lists into a single text file where the before and after match (e.g., aOld => aNew, bOld => bNew). Any insight would be appreciated. Thanks!


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 root project folder
		set astid to AppleScript's text item delimiters
		set AppleScript's text item delimiters to linefeed
		set _BEFORE to all_files as text
		set AppleScript's text item delimiters to astid
		
		--Open the file for write access, creating it if it doesn't exist.
		set fileAccess to (open for access file ((projectFolder as text) & fileSuffix & "_BEFORE") with write permission)
		try -- Ensure that any errors don't stop the script before it's closed the access channel.
			set eof fileAccess to 0 -- Empty the file as a formality.
			write _BEFORE as «class utf8» to fileAccess -- Write the text to the file as UTF-8.
		end try
		close access fileAccess
		
		--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
			
			--check if the current file from our list (based on index-number) has 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
		set astid to AppleScript's text item delimiters
		set AppleScript's text item delimiters to linefeed
		set _AFTER to all_files as text
		set AppleScript's text item delimiters to astid
		
		--Open the file for write access, creating it if it doesn't exist.
		set fileAccess to (open for access file ((projectFolder as text) & fileSuffix & "_AFTER") with write permission)
		try -- Ensure that any errors don't stop the script before it's closed the access channel.
			set eof fileAccess to 0 -- Empty the file as a formality.
			write _AFTER as «class utf8» to fileAccess -- Write the text to the file as UTF-8.
		end try
		close access fileAccess
		
		display notification "File Rename Complete " & index & " files with '" & projCode & "_" & fileSuffix & "' for you."
	end tell

Hi.

it’s probably a good idea to get the paths with the new names while the renaming’s taking place, in case the new names cause any reordering of the items in the Finder. You could use text and lists throughout and only use the Finder to rename the files:


--pick files
set all_files to (choose file with prompt "SELECT " & fileSuffix & " FILES:" with multiple selections allowed)

--get _BEFORE_AND_AFTER list, initially just the _BEFORE items
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set _BEFORE_AND_AFTER to paragraphs of (all_files as text) -- List of the original paths.
-- TIDs not reset yet as they're changed a lot during the repeat.

--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 (count _BEFORE_AND_AFTER)
	--using our index, we select the appropriate path from our list
	set old_path to item |index| of _BEFORE_AND_AFTER
	
	-- Get both the path to the file's container and the name of the file, omitting any trailing ":" if the "file"'s a bundle.
	if (old_path ends with ":") then set old_path to text 1 thru -2 of old_path
	set AppleScript's text item delimiters to ":"
	set container_path to text 1 thru text item -2 of old_path
	set old_name to text item -1 of old_path
	
	--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later
	set file_index to text -2 thru -1 of ((100 + |index|) as text)
	
	--check if the current file from our list (based on index-number) has any file-extension
	if (old_name contains ".") then
		set AppleScript's text item delimiters to "."
		set file_extension to "." & text item -1 of old_name
	else
		set file_extension to ""
	end if
	
	--rename file, add the sequential number from 'index' and add the file-extension to it
	set new_name to projCode & fileSuffix & file_index & file_extension
	tell application "Finder" to set the name of item old_path to new_name
	
	--update the entry in the _BEFORE_AND_AFTER list
	set new_path to container_path & ":" & new_name
	set item |index| of _BEFORE_AND_AFTER to old_path & " => " & new_path
end repeat

--coerce the _BEFORE_AND_AFTER list to text and reset the delimiters
set AppleScript's text item delimiters to linefeed
set _BEFORE_AND_AFTER to _BEFORE_AND_AFTER as text
set AppleScript's text item delimiters to astid

--Open the file for write access, creating it if it doesn't exist.
set fileAccess to (open for access file ((projectFolder as text) & fileSuffix & "_BEFORE_AND_AFTER") with write permission)
try -- Ensure that any errors don't stop the script before it's closed the access channel.
	set eof fileAccess to 0 -- Empty the file as a formality.
	write _BEFORE_AND_AFTER as «class utf8» to fileAccess -- Write the text to the file as UTF-8.
end try
close access fileAccess

display notification "File Rename Complete " & |index| & " files with '" & projCode & "_" & fileSuffix & "' for you."

Edit: Corrected as per ldicroce’s comments in the following post.

Hey I found two small typos in one of the last lines:
" write _AFTER as «class utf8» to fileAccess"
it should be:
“write _BEFORE_AND_AFTER as «class utf8» to fileAccess”

display notification “File Rename Complete " & index & " files with '” & projCode & “_” & fileSuffix & “’ for you.”
it should be:
display notification “File Rename Complete " & (|index| as text) & " files with '” & projCode & “_” & fileSuffix & “’ for you.”

And I have a question:
Why do you use |index| instead of something simpler such as “i”?
Is that any particular meaning of the vertical line (pipe)?

Thanks !

The bookmarked pipe is the mathematical symbol for absolute values; as used here, they enforce the meaning of the variable, which is necessary because “index” is a reserved word. While “i” is simpler, it’s also not at all descriptive, which makes it a poor choice for a variable.

Edit: The pipe enforces the literality of the variable itself, like quotation marks for reserved words.

I am not sure I have understood.
The line “repeat with x from 1 to 10” implies already that x is an absolute number. So no need to enforce it. Is that correct? I might miss something …

To have a descriptive name for this variable would the name “my_index” also be equally good? Or the pipe is really acting mathematically on that value? In other words, is the pipe just a text character or a mathematic operator?

I am saying this since when someone read that script (like myself) might get confused by the pipe symbol …

Thanks !

Thanks! They’re now corrected.

The as text isn’t strictly necessary, because the value of |index| is automatically coerced to text when it’s concatenated to the text "File Rename Complete ".

DarthAztek used index in his original post, but as Marc’s pointed out, that’s a reserved keyword — or at least is on our machines. (I’m not sure what’s reserving it, though.) I wanted to use something which looked as similar to the original as possible, so I simply added the vertical bars. index is a reserved keyword; |index| is a legitimate label to use for a variable in AppleScript.

Got it.
Thanks to both of you !

I should have added that the purpose of vertical bars in AppleScript is to allow terms and characters which wouldn’t normally be allowed to be used as/in labels:

set |index| to 7
set |my favourite variable| to "Hello"
set |x - 1| to x - 1
set |⌘| to current application

But they should really only be used where there are no sensible alternatives. :slight_smile:

Hey folks, thanks so much for the assist. My first attempt gave me the error that said “new_name” was not defined. Did I miss something? I’d prefer not to ‘code bomb’ you guys with the entire script, but if needed for context, I’ll do so.

Hi DarthAztek.

I can’t see why you should be getting that error. In my code above, new_name is set near the bottom of the repeat, is immediately used to rename the file, and is then appended to the container folder path to create an _AFTER path (new_path) to put in the text file. These are the only places it’s used.

There are a few variables which aren’t defined in the code — ie. fileSuffix, projCode, and projFolder — which aren’t defined in your posted script either. I’ve assumed these are set in code which precedes the snippet you posted. Both projCode and fileSuffix are used in the setting of new_name.

I’m just about to go away for a few days, so if you post again and I don’t reply immediately, it won’t be because I’ve lost interest. :slight_smile:

Thanks and duly noted. Here’s the full script—with your additions—to help with the context. I’m hoping won’t be a horrible mess to swim through. Don’t mind my notes elsewhere in the script, I’m making tweaks elsewhere to it.


--SETUP: version 2.00a
--set delimiters for filename sequence
set text item delimiters to "."
--set default loop count
set seqCount to 1

--get job code, format ABCDEXX###
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 for " & projCode

--choose zip/nozip here, else jump to startPrep
display dialog "NEED TO ZIP/RENAME ZIPPED FONTS?" buttons {"Zip Fonts", "Rename Zipped", "Skip"} default button 1 with icon caution
set w to button returned of result
if w is "Zip Fonts" then
	--zip fonts folder
	set typePreviewNeed to "yes"
	zipFonts(projectFolder, projCode, seqCount, typePreviewNeed)
else if w is "Rename Zipped" then
	--rename zipped font file
	set typePreviewNeed to "yes"
	renameZip(projectFolder, projCode, seqCount, typePreviewNeed)
else if w is "Skip" then
	--check for PDF 
	set typePreviewNeed to "no"
	checkPDF(projCode, projectFolder, seqCount, typePreviewNeed)
end if

--ZIP FONT FOLDER
on zipFonts(projectFolder, projCode, seqCount, typePreviewNeed)
	tell application "Finder"
		--set zip filename append pre suffix
		set zipSuffix to "_TYPEFACES"
		
		--pick font folder
		set inputFolder to choose folder default location projectFolder with prompt "SELECT FONT FOLDER for " & projCode
		
		--path to _Fonts_ReadMe.txt
		set fontsReadMe to (path to me as string) & "Contents:Resources:_Fonts_ReadMe.txt"
		--duplicate file to font folder
		set dupeRM to duplicate of fontsReadMe to inputFolder
		
		--execute shell command to zip
		set qpp to quoted form of POSIX path of inputFolder
		do shell script "cd $(dirname " & qpp & ")
		zip -r  \"$(basename " & projCode & "_TYPEFACES" & ").zip\" \"$(basename " & qpp & ")\""
		--delete the original font folder
		delete folder inputFolder
		
		--notify completion
		display notification "FONTS ZIPPED"
	end tell
	
	--go to next step
	checkPDF(projCode, projectFolder, seqCount, typePreviewNeed)
end zipFonts

--RENAME ZIPPED FONT FOLDER
on renameZip(projectFolder, projCode, seqCount, typePreviewNeed)
	tell application "Finder"
		set mainZIP to (choose file default location projectFolder with prompt "SELECT ZIPPED FONTS for " & projCode)
		--get the filename to save the extension
		set mainZIPCount to text items of (get name of mainZIP)
		--pull original filename extension
		if number of mainZIPCount is 1 then
			set mainExt to ""
		else
			set mainExt to "." & item -1 of mainZIPCount
		end if
		--rename file with extension (Finder removes extensions by default when renaming)
		set the name of mainZIP to projCode & "_TYPEFACES" & mainExt as string
		--copy fontsReadMe to projectFolder
		set fontsReadMe to (path to me as string) & "Contents:Resources:_Fonts_ReadMe.txt"
		set dupeRM to duplicate of fontsReadMe to projectFolder
	end tell
	
	--go to next step
	checkPDF(projCode, projectFolder, seqCount, typePreviewNeed)
end renameZip

on checkPDF(projCode, projectFolder, seqCount, typePreviewNeed)
	display dialog "PROJECT CONTAINS PDF OF MECHANICAL?" buttons {"Yes", "No", "Cancel"} default button 1 with icon caution
	set v to button returned of result
	if v is "Yes" then
		--go to PDF process
		prepPDF(projCode, projectFolder, seqCount, typePreviewNeed)
	else if v is "No" then
		--skip step and start prep
		display notification "SKIPPING STEP PLEASE CREATE PDF MANUALLY"
	else if v is "Cancel" then
		display notification "PROCESS CANCELLED"
		cancel
	end if
	startPrep(projCode, projectFolder, seqCount, typePreviewNeed)
end checkPDF

on prepPDF(projCode, projectFolder, seqCount, typePreviewNeed)
	tell application "Finder"
		--DESIGNATE MAIN PDF
		set mainPDF to (choose file default location projectFolder with prompt "SELECT MAIN PDF FILE for " & projCode)
		--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 with extension (Finder removes extensions by default when renaming)
		set the name of mainPDF to projCode & "_PDF01" & mainExt as string
	end tell
	
	--continue to next step
	startPrep(projCode, projectFolder, seqCount, typePreviewNeed)
end prepPDF

on startPrep(projCode, projectFolder, seqCount, typePreviewNeed)
	--try omitting the tells?
	tell application "Finder"
		--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"}
		--copy font typeface preview file to PREVIEW folder
		if typePreviewNeed = "yes" then
			set typePreview to (path to me as string) & "Contents:Resources:_TYPEFACES.jpg"
			set dupeTP to (duplicate of typePreview to folder of folder projectFolder with name) = "PREVIEWS" --rework line of code, not working
			set name of dupeTP to newName
			set newName of dupeRM to projCode & "_TYPEFACES.jpg"
		end if
		
		--DESIGNATE MAIN MECHANICAL
		set mainMech to (choose file default location projectFolder with prompt "SELECT MAIN MECHANICAL FILE for " & projCode)
		--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 with extension (Finder removes extensions by default when renaming)
		set the name of mainMech to projCode & mainExt as string
		
	end tell
	
	--start next step
	initSeq(projCode, projectFolder, seqCount)
end startPrep

--RENAME/SEQUENCE SUPPORT FILES
--check current initSeq count
--for later: put in code to bring app to the front during the seqArt, seqBit, etc loops?
on initSeq(projCode, projectFolder, seqCount)
	--default sequence order
	if seqCount = 1 then
		seqART(projCode, projectFolder, seqCount)
	else if seqCount = 2 then
		seqBIT(projCode, projectFolder, seqCount)
	else if seqCount = 3 then
		seqIL(projCode, projectFolder, seqCount)
	else if seqCount = 4 then
		seqLYRD(projCode, projectFolder, seqCount)
	else if seqCount > 4 then
		--extract project code for folder prepend
		set prePend to text -5 thru -1 of projCode
		--prepend project code to projectFolder name
		tell application "System Events" to set name of projectFolder to (prePend & " - " & (get name of projectFolder))
		--reset count for next project
		set seqCount to 1
		display notification "PLEASE CREATE PREVIEWS AND RELINK TO MECHANICAL." with title "PROJECT " & projCode & " PREP COMPLETED." sound name "Purr"
		delay 2
		quit
	end if
end initSeq

--sequence through different support files
--sequence _ART
on seqART(projCode, projectFolder, seqCount)
	set fileSuffix to "_ART"
	tell application "System Events" to set frontmost of process "SuperPrepScrip_v2_00" to true --comment out if this doesn't keep the dialog box up front; may not work in script test format
	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, projectFolder, projCode, seqCount)
	else if x is "Skip" then
		set seqCount to seqCount + 1
		seqBIT(projCode, projectFolder, seqCount)
	else if x is "Cancel" then
		delay 2
		display notification "PROCESS CANCELLED" sound name "Basso"
		cancel
	end if
end seqART

--sequence _BIT
on seqBIT(projCode, projectFolder, seqCount)
	set fileSuffix to "_BIT"
	tell application "System Events" to set frontmost of process "SuperPrepScrip_v2_00" to true --comment out if this doesn't keep the dialog box up front; may not work in script test format
	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, projectFolder, projCode, seqCount)
	else if x is "Skip" then
		set seqCount to seqCount + 1
		seqIL(projCode, projectFolder, seqCount)
	else if x is "Cancel" then
		delay 2
		display notification "PROCESS CANCELLED" sound name "Basso"
		cancel
	end if
end seqBIT

--sequence _IL
on seqIL(projCode, projectFolder, seqCount)
	set fileSuffix to "_IL"
	tell application "System Events" to set frontmost of process "SuperPrepScrip_v2_00" to true --comment out if this doesn't keep the dialog box up front; may not work in script test format
	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, projectFolder, projCode, seqCount)
	else if x is "Skip" then
		set seqCount to seqCount + 1
		seqLYRD(projCode, projectFolder, seqCount)
	else if x is "Cancel" then
		delay 2
		display notification "PROCESS CANCELLED" sound name "Basso"
		cancel
	end if
end seqIL

--sequence _LYRD
on seqLYRD(projCode, projectFolder, seqCount)
	set fileSuffix to "_LYRD"
	tell application "System Events" to set frontmost of process "SuperPrepScrip_v2_00" to true --comment out if this doesn't keep the dialog box up front; may not work in script test format
	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, projectFolder, projCode, seqCount)
	else if x is "Skip" then
		set seqCount to seqCount + 1
		initSeq(projCode, projectFolder, seqCount)
	else if x is "Cancel" then
		delay 2
		display notification "PROCESS CANCELLED" sound name "Basso"
		cancel
	end if
end seqLYRD

--rename support files in sequence
on seqFILES(fileSuffix, projectFolder, projCode, seqCount)
	--RENAME ALL SUPPORT FILES IN SEQUENCE
	--tell application "Finder"
	--pick files
	set all_files to (choose file with prompt "SELECT " & fileSuffix & " FILES:" with multiple selections allowed)
	
	--get _BEFORE_AND_AFTER list, initially just the _BEFORE items
	set astid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to linefeed
	set _BEFORE_AND_AFTER to paragraphs of (all_files as text) -- List of the original paths.
	-- TIDs not reset yet as they're changed a lot during the repeat.
	
	--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 (count _BEFORE_AND_AFTER)
		--using our index, we select the appropriate path from our list
		set old_path to item |index| of _BEFORE_AND_AFTER
		
		-- Get both the path to the file's container and the name of the file, omitting any trailing ":" if the "file"'s a bundle.
		if (old_path ends with ":") then set old_path to text 1 thru -2 of old_path
		set AppleScript's text item delimiters to ":"
		set container_path to text 1 thru text item -2 of old_path
		set old_name to text item -1 of old_path
		
		--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later
		set file_index to text -2 thru -1 of ((100 + |index|) as text)
		
		--check if the current file from our list (based on index-number) has any file-extension
		if (old_name contains ".") then
			set AppleScript's text item delimiters to "."
			set file_extension to "." & text item -1 of old_name
		else
			set file_extension to ""
		end if
		
		--rename file, add the sequential number from 'index' and add the file-extension to it
		set new_name to projCode & fileSuffix & file_index & file_extension
		tell application "Finder" to set the name of item old_path to new_name
		
		--update the entry in the _BEFORE_AND_AFTER list
		set new_path to container_path & ":" & new_name
		set item |index| of _BEFORE_AND_AFTER to old_path & " => " & new_path
	end repeat
	
	--coerce the _BEFORE_AND_AFTER list to text and reset the delimiters
	set AppleScript's text item delimiters to linefeed
	set _BEFORE_AND_AFTER to _BEFORE_AND_AFTER as text
	set AppleScript's text item delimiters to astid
	
	--Open the file for write access, creating it if it doesn't exist.
	set fileAccess to (open for access file ((projectFolder as text) & fileSuffix & "_BEFORE_AND_AFTER") with write permission)
	try -- Ensure that any errors don't stop the script before it's closed the access channel.
		set eof fileAccess to 0 -- Empty the file as a formality.
		write _BEFORE_AND_AFTER as «class utf8» to fileAccess -- Write the text to the file as UTF-8.
	end try
	close access fileAccess
	
	display notification "File Rename Complete " & |index| & " files with '" & projCode & "_" & fileSuffix & "' for you."
	--end tell
	
	--add in increment to seqCount and restart sequence
	set seqCount to seqCount + 1
	initSeq(projCode, projectFolder, seqCount)
	
end seqFILES

Hi.

Well. I’m afraid it’s the same question mark, even with the full script. There are only two lines in the entire code which try to read the contents of a variable called new_name and they immediately follow a line which sets its value. Unless you’ve accidentally deleted this line or commented it out, there’s no way you can be getting an error saying that “The variable new_name is not defined.” :confused:

Ohyehgawds, it’s not “new_name” that’s throwing the error, it’s “newName” that happens earlier in the script during the startPrep handler. I feel dumb now, staring at this code for like a week, especially since I left myself a note to fix the code (DUH) after trying to tweak it. No wonder I’m hitting a wall. I’ve since taken out “newName” to not confuse myself again.

The goal was to put a copy of a jpg into the newly-created “PREVIEWS” folder from the app version of the script (in the package’s “Resouces” folder), snippet of the borked code below:

		if typePreviewNeed = "yes" then
			set typePreview to (path to me as string) & "Contents:Resources:_TYPEFACES.jpg"
			set dupeTP to (duplicate of typePreview to folder of folder projectFolder with name) = "PREVIEWS" --rework line of code, not working
			set name of dupeTP to projCode & "_TYPEFACES.jpg"--erroring out, unable to rename the file.
		end if

It’s similar to the end of the renameZip handler earlier in the script, snipped below:

--copy fontsReadMe to projectFolder
		set fontsReadMe to (path to me as string) & "Contents:Resources:_Fonts_ReadMe.txt"
		set dupeRM to duplicate of fontsReadMe to projectFolder

Sorry about my error causing the confusion!

Aha! I might have noticed that myself if I’d read the entire script. But I just used Find… in Script Editor to see where new_name appeared in the code. :rolleyes:

Apart from newName only being set after it’s used, there are a few issues with the ‘set dupeTP …’ line.

  1. duplicate is a command, not a property, so it shouldn’t be followed by of.
  2. typePreview has been set to text, so it should either be coerced to alias or be preceded by file or item in the duplicate command. Alternatively, you may prefer to use path to resource (another StandardAdditions command), which returns an alias anyway.
  3. folder of happens to return the folder in which a Finder item occurs, but for clarity and conformity with the Finder’s dictionary, it should be container of (assuming that this is actually what’s wanted).
  4. The Finder’s duplicate command doesn’t have a name or with name parameter.
  5. The line sets dupeTP to the result of testing whether or not the result of duplicate is the text “PREVIEWS” — that is, the boolean false — so you won’'t be able to set its name to anything in the following line.

	if typePreviewNeed = "yes" then
		-- set typePreview to ((path to me as text) & "Contents:Resources:_TYPEFACES.jpg") as alias
		set typePreview to (path to resource "_TYPEFACES.jpg" in bundle (path to me))
		set dupeTP to (duplicate typePreview to container of folder projectFolder)
		set name of dupeTP to projCode & "_TYPEFACES.jpg"
	end if

Thanks for the assist! That helps immensely. It does correctly drop a copy of the resource file, but it put it into the root folder (the container part of the line), rather into an existing subfolder, which would be projectFolder/PREVIEWS., but I’ve been unsuccessful in the proper syntax for that.

I think you mean this:

set dupeTP to (duplicate typePreview to folder "PREVIEWS" of folder projectFolder)

{facepalm} I swear, the more I learn, the dumber I feel. But hey, so long as I’m learning, right? It works perfectly now!

One final question: during the on seqART, BIT, IL, and LYRD handlers, I noticed that if “Skip” is clicked, the next handler fires off (seqFiles to initSeq to repeat until it goes through those first four handlers) and brings the next dialog box up. No problem.

However, say seqART’s dialog box is clicked “yes” and follows through the procedure, the dialog box for the next step (which would be seqBIT), does not automatically come to the front—it does the little dock bounce—necessitating Alt-Tabbing or manually selecting back to the app. Is there a way to have those dialog boxes pop up in front? Thanks a million!

Hi.

Although they’re StandardAdditions commands, the display … and choose … commands should be thought of as being user interaction commands executed by (or in) particular applications. If they’re in tell application … statements, the dialogs are displayed by the applications addressed, otherwise they’re displayed by the application running the script.

Your seq… handlers bring a process called “SuperPrepScrip_v2_00” to the front and then the script attempts to display the dialogs. Is “SuperPrepScrip_v2_00” the name of your script? Is it running as an application? If so, it would be simpler to use something like:

tell me to activate
display dialog "Rename/Sequence _ART?" buttons {"Yes", "Skip", "Cancel"} default button 1 with icon caution

If “SuperPrepScrip_v2_00” is some other application and you want it to display the dialog:

tell application "SuperPrepScrip_v2_00"
	activate
	display dialog "Rename/Sequence _ART?" buttons {"Yes", "Skip", "Cancel"} default button 1 with icon caution
end tell

The script probably starts out being frontmost, but in prepPDF and startPrep, choose file is used in Finder tell statements, which is possibly having the side-effect of bringing the Finder to the front. (I don’t see why it should, but that’s what happens nowadays when tested in Script Editor.) In prefPDF, you can simply move the ‘set mainPDF …’ line up to before the ‘tell’ line, which may stop the Finder coming to the front there. In startPrep, you can either end the Finder tell statement immediately before the ‘set mainMech …’ line and start another immediately after it (best) or prefix ‘set mainMech’ with 'tell me to ’ (should also work). Yet another possibility would be to farm choose file out to its own handler, which can be called with the necessary parameters:

on prepPDF(projCode, projectFolder, seqCount, typePreviewNeed)
	set mainPDF to chooseFile(projectFolder, "SELECT MAIN PDF FILE for " & projCode)
	tell application "Finder"
		
		-- Blah blah.
		
	end tell
end prepPDF

on startPrep(projCode, projectFolder, seqCount, typePreviewNeed)
	tell application "Finder"
		-- Blah blah.
		
		set mainMech to my chooseFile(projectFolder, "SELECT MAIN MECHANICAL FILE for " & projCode)
		
		-- More blah.
	end tell
end startPrep

on chooseFile(defaultLocation, thePrompt)
	tell me to activate -- May not be necessary.
	return (choose file default location defaultLocation with prompt thePrompt)
end chooseFile

A similar thing can be done with the display dialogs.

There are several solutions. You just have to choose one which suits your purposes.

Yes it is an standalone app, and moving the set to before the tells made a HUGE difference. Thanks so much!