Watched Folder Script File Naming Compiling Error

I wrote a Watched Folder script which, among other things, will remove the DTP app. extension (.qxp, .indd, etc.) from the postscript file before transferring the .ps file to Distiller Watched Folder.

The script works if I run it natively but when I add code for the Watched Folder, “on adding folder items to ff after receiving L” and “end adding folder items to” I get the Syntax Error: Expected “end” but found “on” at line: on set_item_name(this_item, new_item_name).

I assume it’s because the word “on” is being confused as a Watched Folder Action.

Do you have any ideas for a wordaround? Any help would be greatly appreciated.:confused:

on adding folder items to ff after receiving L
--Check to ensure Distiller is running.
tell application "System Events"
	set myList to (name of every process)
end tell
if (myList contains "Distiller") is false then
	display dialog "Acrobat Distiller has not been launched.

Please launch Distiller, right-click on its dock icon and select Open at Login.

If the PostScript-PDF workflow process does not begin, remove the current PostScript file and regenerate a new PostScript file or remove the current PostScript file and log out and log back in." buttons {"OK"} default button 1
	return
end if

--Check to ensure folder.joboptions are in Watched Folders.
tell application "Finder"
	set posixPath1 to ("/Users/Shared/Work/00_PDF_HI_RES/")
	set fileURL1 to posixPath1 as POSIX file
	set theAlias1 to fileURL1 as alias
	tell application "Finder" to set finderRef1 to item theAlias1
	set theFolder1 to theAlias1
	
	try
		if file "folder.joboptions" of theFolder1 exists then
		else
			display dialog "The file, folder.joboptions, cannot be found in the 00_PDF_HI_RES folder of the Work folder. Please take note of this message and contact your system administrator immediately." buttons {"OK"} default button 1
			return
		end if
	end try
end tell

tell application "Finder"
	set posixPath2 to ("/Users/Shared/Work/00_PDF_LO_RES/")
	set fileURL2 to posixPath2 as POSIX file
	set theAlias2 to fileURL2 as alias
	tell application "Finder" to set finderRef2 to item theAlias2
	set theFolder2 to theAlias2
	
	try
		if file "folder.joboptions" of theFolder2 exists then
		else
			display dialog "The file, folder.joboptions, cannot be found in the 00_PDF_LO_RES folder of the Work folder. Please take note of this message and contact your system administrator immediately." buttons {"OK"} default button 1
			return
		end if
	end try
end tell

--Find PS files in ¢ Postscripts folder and duplicate to HiRes-Trash folder.	
tell application "Finder"
	set posixPath3 to ("/Users/Shared/Work/¢ Postscripts/")
	set fileURL3 to posixPath3 as POSIX file
	set theAlias3 to fileURL3 as alias
	tell application "Finder" to set finderRef3 to item theAlias3
	set psFolder to theAlias3
	
	set posixPath4 to ("/Users/Shared/Work/¢ Postscripts/HiRes-Trash/")
	set fileURL4 to posixPath4 as POSIX file
	set theAlias4 to fileURL4 as alias
	tell application "Finder" to set finderRef4 to item theAlias4
	set HiResTrash to theAlias4
	
	try
		if ((items of psFolder) whose name ends with (".ps")) exists then
			duplicate ((items of psFolder) whose name ends with (".ps")) to HiResTrash with replacing
		end if
	end try
end tell

--Delete DTP file extensions for LoRes.
tell application "Finder"
	set posixPath5 to ("/Users/Shared/Work/¢ Postscripts/")
	set fileURL5 to posixPath5 as POSIX file
	set theAlias5 to fileURL5 as alias
	tell application "Finder" to set finderRef5 to item theAlias5
	set psFolder to theAlias5
	
	try
		if ((items of psFolder) whose name ends with (".ps")) exists then
			set source_folder to psFolder as alias
			set the search_parameter to name of ((items of psFolder) whose name ends with (".ps"))
			set search_string to {".qxp"}
			set replacement_string to {""}
			
			set item_list to list folder psFolder without invisibles
			set source_folder to psFolder as string
			repeat with i from 1 to number of items in item_list
				set this_item to item i of item_list
				set this_item to (source_folder & this_item) as alias
				set this_info to info for this_item
				set current_name to name of this_info
				set change_flag to false
				
				if current_name contains search_string then
					set the change_flag to true
					if change_flag is true then
						set AppleScript's text item delimiters to search_string
						set text_item_list to every text item of current_name
						set AppleScript's text item delimiters to replacement_string
						set new_item_name to text_item_list as string
						set AppleScript's text item delimiters to ""
						my set_item_name(this_item, new_item_name)
					end if
				end if
			end repeat
		end if
	end try
end tell

on set_item_name(this_item, new_item_name)
	tell application "Finder"
		set parent_container_path to (the container of this_item) as text
		if not (exists item (the parent_container_path & new_item_name)) then
			try
				set the name of this_item to new_item_name
				my set_item_name(this_item, new_item_name)
			end try
		end if
	end tell
end set_item_name

tell application "Finder"
	set posixPath6 to ("/Users/Shared/Work/¢ Postscripts/")
	set fileURL6 to posixPath6 as POSIX file
	set theAlias6 to fileURL6 as alias
	tell application "Finder" to set finderRef6 to item theAlias6
	set psFolder to theAlias6
	
	try
		if ((items of psFolder) whose name ends with (".ps")) exists then
			set source_folder to psFolder as alias
			set the search_parameter to name of ((items of psFolder) whose name ends with (".ps"))
			set search_string to {".indd"}
			set replacement_string to {""}
			
			set item_list to list folder psFolder without invisibles
			set source_folder to psFolder as string
			repeat with i from 1 to number of items in item_list
				set this_item to item i of item_list
				set this_item to (source_folder & this_item) as alias
				set this_info to info for this_item
				set current_name to name of this_info
				set change_flag to false
				
				if current_name contains search_string then
					set the change_flag to true
					if change_flag is true then
						set AppleScript's text item delimiters to search_string
						set text_item_list to every text item of current_name
						set AppleScript's text item delimiters to replacement_string
						set new_item_name to text_item_list as string
						set AppleScript's text item delimiters to ""
						my set_item_name1(this_item, new_item_name)
					end if
				end if
			end repeat
		end if
	end try
end tell

on set_item_name1(this_item, new_item_name)
	tell application "Finder"
		set parent_container_path to (the container of this_item) as text
		if not (exists item (the parent_container_path & new_item_name)) then
			try
				set the name of this_item to new_item_name
				my set_item_name1(this_item, new_item_name)
			end try
		end if
	end tell
end set_item_name1

--Delete DTP file extensions and add "HR" suffix for HiRes.
tell application "Finder"
	set posixPath7 to ("/Users/Shared/Work/¢ Postscripts/HiRes-Trash/")
	set fileURL7 to posixPath7 as POSIX file
	set theAlias7 to fileURL7 as alias
	tell application "Finder" to set finderRef7 to item theAlias7
	set HiResTrash to theAlias7
	
	try
		if ((items of HiResTrash) whose name ends with (".ps")) exists then
			set source_folder to HiResTrash as alias
			set the search_parameter to name of ((items of HiResTrash) whose name ends with (".ps"))
			set search_string to {".qxp"}
			set replacement_string to {"HR"}
			
			set item_list to list folder HiResTrash without invisibles
			set source_folder to HiResTrash as string
			repeat with i from 1 to number of items in item_list
				set this_item to item i of item_list
				set this_item to (source_folder & this_item) as alias
				set this_info to info for this_item
				set current_name to name of this_info
				set change_flag to false
				
				if current_name contains search_string then
					set the change_flag to true
					if change_flag is true then
						set AppleScript's text item delimiters to search_string
						set text_item_list to every text item of current_name
						set AppleScript's text item delimiters to replacement_string
						set new_item_name to text_item_list as string
						set AppleScript's text item delimiters to ""
						my set_item_name2(this_item, new_item_name)
					end if
				end if
			end repeat
		end if
	end try
end tell

on set_item_name2(this_item, new_item_name)
	tell application "Finder"
		set parent_container_path to (the container of this_item) as text
		if not (exists item (the parent_container_path & new_item_name)) then
			try
				set the name of this_item to new_item_name
				my set_item_name2(this_item, new_item_name)
			end try
		end if
	end tell
end set_item_name2


tell application "Finder"
	set posixPath8 to ("/Users/Shared/Work/¢ Postscripts/HiRes-Trash/")
	set fileURL8 to posixPath8 as POSIX file
	set theAlias8 to fileURL8 as alias
	tell application "Finder" to set finderRef8 to item theAlias8
	set HiResTrash to theAlias8
	
	try
		if ((items of HiResTrash) whose name ends with (".ps")) exists then
			set source_folder to HiResTrash as alias
			set the search_parameter to name of ((items of HiResTrash) whose name ends with (".ps"))
			set search_string to {".indd"}
			set replacement_string to {"HR"}
			
			set item_list to list folder HiResTrash without invisibles
			set source_folder to HiResTrash as string
			repeat with i from 1 to number of items in item_list
				set this_item to item i of item_list
				set this_item to (source_folder & this_item) as alias
				set this_info to info for this_item
				set current_name to name of this_info
				set change_flag to false
				
				if current_name contains search_string then
					set the change_flag to true
					if change_flag is true then
						set AppleScript's text item delimiters to search_string
						set text_item_list to every text item of current_name
						set AppleScript's text item delimiters to replacement_string
						set new_item_name to text_item_list as string
						set AppleScript's text item delimiters to ""
						my set_item_name3(this_item, new_item_name)
					end if
				end if
			end repeat
		end if
	end try
end tell

on set_item_name3(this_item, new_item_name)
	tell application "Finder"
		set parent_container_path to (the container of this_item) as text
		if not (exists item (the parent_container_path & new_item_name)) then
			try
				set the name of this_item to new_item_name
				my set_item_name3(this_item, new_item_name)
			end try
		end if
	end tell
end set_item_name3

--Move PS files to 00_PDF_LO_RES In.
tell application "Finder"
	set posixPath9 to ("/Users/Shared/Work/¢ Postscripts/")
	set fileURL9 to posixPath9 as POSIX file
	set theAlias9 to fileURL9 as alias
	tell application "Finder" to set finderRef9 to item theAlias9
	set psFolder to theAlias9
	
	set posixPath10 to ("/Users/Shared/Work/00_PDF_LO_RES/In/")
	set fileURL10 to posixPath10 as POSIX file
	set theAlias10 to fileURL10 as alias
	tell application "Finder" to set finderRef10 to item theAlias10
	set LoResIn to theAlias10
	
	try
		if ((items of psFolder) whose name ends with (".ps")) exists then
			get every item of psFolder whose name ends with (".ps")
			move (every item of psFolder whose name ends with (".ps")) to LoResIn with replacing
		end if
	end try
end tell

--Move PS files to 00_PDF_HI_RES In.
tell application "Finder"
	set posixPath11 to ("/Users/Shared/Work/¢ Postscripts/HiRes-Trash/")
	set fileURL11 to posixPath11 as POSIX file
	set theAlias11 to fileURL11 as alias
	tell application "Finder" to set finderRef11 to item theAlias11
	set HiResTrash to theAlias11
	
	set posixPath12 to ("/Users/Shared/Work/00_PDF_HI_RES/In/")
	set fileURL12 to posixPath12 as POSIX file
	set theAlias12 to fileURL12 as alias
	tell application "Finder" to set finderRef12 to item theAlias12
	set HiResIn to theAlias12
	
	try
		if ((items of HiResTrash) whose name ends with (".ps")) exists then
			get every item of HiResTrash whose name ends with (".ps")
			move (every item of HiResTrash whose name ends with (".ps")) to HiResIn with replacing
		end if
	end try
end tell
end adding folder items to

Model: Dual 2.7 GHz PPC G5
AppleScript: 1.10.7
Browser: Safari 522.12.1
Operating System: Mac OS X (10.4)

You need to keep your functions separate:


on adding....




end adding...
on funct1


end funct1
on funct2


end funct2

Hi,

I cleaned up your script a bit, it should be much faster now


on adding folder items to ff after receiving L
	--Check to ensure Distiller is running.
	tell application "System Events" to set myList to (name of every process)
	if (myList contains "Distiller") is false then
		display dialog "Acrobat Distiller has not been launched.

Please launch Distiller, right-click on its dock icon and select Open at Login.

If the PostScript-PDF workflow process does not begin, remove the current PostScript file and regenerate a new PostScript file or remove the current PostScript file and log out and log back in." buttons {"OK"} default button 1
		return
	end if
	
	set workFolder to ((path to shared documents as text) & "Work:")
	set HiResFolder to (workFolder & "00_PDF_HI_RES:")
	set LowResFolder to (workFolder & "00_PDF_LOW_RES:")
	set psFolder to (workFolder & "¢ Postscripts:")
	set HiResTrashFolder to (psFolder & "HiRes-Trash:")
	set LowResInFolder to LowResFolder & "In:"
	set HiResInFolder to HiResFolder & "In:"
	
	--Check to ensure folder.joboptions are in Watched Folders.
	if checkJoboptions(LowResFolder) is false then return
	if checkJoboptions(HiResFolder) is false then return
	
	--Find PS files in ¢ Postscripts folder and duplicate to HiRes-Trash folder.	
	tell application "Finder" to duplicate (files of folder psFolder whose name extension is "ps") to folder HiResTrashFolder with replacing
	
	--Delete DTP file extensions for LoRes.
	renameFiles(psFolder, "")
	--Delete DTP file extensions and add "HR" suffix for HiRes.
	renameFiles(HiResTrashFolder, "HR")
	
	tell application "Finder"
		--Move PS files to 00_PDF_LO_RES In.
		move (files of folder psFolder whose name extension is "ps") to folder LowResInFolder with replacing
		--Move PS files to 00_PDF_HI_RES In.
		move (files of folder HiResTrashFolder whose name extension is "ps") to folder HiResInFolder with replacing
	end tell
end adding folder items to

on checkJoboptions(_folder)
	try
		(_folder & "folder.joboptions") as alias
		return true
	on error
		tell application "Finder" to display dialog "The file, folder.joboptions, cannot be found in the " & _folder & " folder of the Work folder. Please take note of this message and contact your system administrator immediately." buttons {"OK"} default button 1
		return false
	end try
end checkJoboptions

on renameFiles(_folder, _suffix)
	tell application "Finder"
		repeat with oneFile in (get files of folder _folder whose name extension is "qxd" or name extension is "indd")
			set {name:Nm, name extension:Ex} to oneFile
			set idx to -6
			if Ex is "qxd" then set idx to -5
			set name of contents of oneFile to text 1 thru idx of Nm & _suffix
		end repeat
	end tell
end renameFiles

Thanks for the rewrite Stefan! Your version is stalling on

	--Delete DTP file extensions for LoRes.
	renameFiles(psFolder, "")	
	--Delete DTP file extensions and add "HR" suffix for HiRes.
	renameFiles(HiResTrash, "HR")


AppleScript Error: Finder got an error: Can’t continue renameFiles.

I had to rename the alias paths to posix paths as artists work from a server partition to their Macs.

Everything else works GREAT!

--Check to ensure Distiller is running.
tell application "System Events" to set myList to (name of every process)
if (myList contains "Distiller") is false then
	display dialog "Acrobat Distiller has not been launched.

Please launch Distiller, right-click on its dock icon and select Open at Login.

If the PostScript-PDF workflow process does not begin, remove the current PostScript file and regenerate a new PostScript file or remove the current PostScript file and log out and log back in." buttons {"OK"} default button 1
	return
end if

tell application "Finder"
	set posixPath to ("/Users/Shared/Work/")
	set fileURL to posixPath as POSIX file
	set theAlias to fileURL as alias
	tell application "Finder" to set finderRef to item theAlias
	set workFolder to theAlias
	
	set posixPath1 to ("/Users/Shared/Work/00_PDF_HI_RES/")
	set fileURL1 to posixPath1 as POSIX file
	set theAlias1 to fileURL1 as alias
	tell application "Finder" to set finderRef1 to item theAlias1
	set HiResFolder to theAlias1
	
	set posixPath2 to ("/Users/Shared/Work/00_PDF_LO_RES/")
	set fileURL2 to posixPath2 as POSIX file
	set theAlias2 to fileURL2 as alias
	tell application "Finder" to set finderRef2 to item theAlias2
	set LoResFolder to theAlias2
	
	set posixPath3 to ("/Users/Shared/Work/¢ Postscripts/")
	set fileURL3 to posixPath3 as POSIX file
	set theAlias3 to fileURL3 as alias
	tell application "Finder" to set finderRef3 to item theAlias3
	set psFolder to theAlias3
	
	set posixPath4 to ("/Users/Shared/Work/¢ Postscripts/HiRes-Trash/")
	set fileURL4 to posixPath4 as POSIX file
	set theAlias4 to fileURL4 as alias
	tell application "Finder" to set finderRef4 to item theAlias4
	set HiResTrashFolder to theAlias4
	
	set posixPath5 to ("/Users/Shared/Work/¢ Postscripts/")
	set fileURL5 to posixPath5 as POSIX file
	set theAlias5 to fileURL5 as alias
	tell application "Finder" to set finderRef5 to item theAlias5
	set psFolder to theAlias5
	
	set posixPath10 to ("/Users/Shared/Work/00_PDF_LO_RES/In/")
	set fileURL10 to posixPath10 as POSIX file
	set theAlias10 to fileURL10 as alias
	tell application "Finder" to set finderRef10 to item theAlias10
	set LowResInFolder to theAlias10
	
	set posixPath12 to ("/Users/Shared/Work/00_PDF_HI_RES/In/")
	set fileURL12 to posixPath12 as POSIX file
	set theAlias12 to fileURL12 as alias
	tell application "Finder" to set finderRef12 to item theAlias12
	set HiResInFolder to theAlias12
	
	--Find PS files in ¢ Postscripts folder and duplicate to HiRes-Trash folder.	
	tell application "Finder" to duplicate (files of folder psFolder whose name extension is "ps") to folder HiResTrashFolder with replacing
	
	--Delete DTP file extensions for LoRes.
	renameFiles(psFolder, "")
	--Delete DTP file extensions and add "HR" suffix for HiRes.
	renameFiles(HiResTrashFolder, "HR")
	
	tell application "Finder"
		--Move PS files to 00_PDF_LO_RES In.
		move (files of folder psFolder whose name extension is "ps") to folder LowResInFolder with replacing
		--Move PS files to 00_PDF_HI_RES In.
		move (files of folder HiResTrashFolder whose name extension is "ps") to folder HiResInFolder with replacing
	end tell
end tell

on checkJoboptions(_folder)
	try
		(_folder & "folder.joboptions") as alias
		return true
	on error
		tell application "Finder" to display dialog "The file, folder.joboptions, cannot be found in the " & _folder & " folder of the Work folder. Please take note of this message and contact your system administrator immediately." buttons {"OK"} default button 1
		return false
	end try
end checkJoboptions

on renameFiles(_folder, _suffix)
	tell application "Finder"
		repeat with oneFile in (get files of folder _folder whose name extension is "qxd" or name extension is "indd")
			set {name:Nm, name extension:Ex} to oneFile
			set idx to -6
			if Ex is "qxd" then set idx to -5
			set name of contents of oneFile to text 1 thru idx of Nm & _suffix
		end repeat
	end tell
end renameFiles

Wrong, my version works, it’s your version, because you’ve changed it :wink:
Remove this useless Finder tell block after the first end if

Your endless “posix to file to alias” coercions aren’t necessary either, this is sufficient


set workFolder to POSIX file "/Users/Shared/Work/" as alias

Beautiful!!! Wish I could code like that!!!:smiley:

Re: the endless “posix to file to alias” coercions: I read somewhere that “set workFolder to POSIX file “/Users/Shared/Work/” as alias” was taking advantage of some sort of bug and the endless “posix to file to alias” coercions was the only way to ensure the path would work. Believe me, it wasn’t any fun writing all of that! Yeesh! As you can probably tell, I used Apple’s Replace Text in Item Names.scpt as my template.

While I’m doling out the praise, care to take a look at another script associated with this one? There are actually three: this one, a simple file transfer script and the third, below, which compares the PDFs to make sure they’re not the same size. (A rudimentary file checker at best.) Unless you have a HiRes/LowRes Comparator in your box of magic scrolls.

on adding folder items to ff after receiving L
	--Find PDF files in LO_RES Out folder and move to HiRes-Trash folder.	
	tell application "Finder"
		set posixPath1 to ("/Users/Shared/Work/00_PDF_LO_RES/Out/")
		set fileURL1 to posixPath1 as POSIX file
		set theAlias1 to fileURL1 as alias
		tell application "Finder" to set finderRef1 to item theAlias1
		set LoResOut to theAlias1
		
		set posixPath2 to ("/Users/Shared/Work/¢ Postscripts/HiRes-Trash/")
		set fileURL2 to posixPath2 as POSIX file
		set theAlias2 to fileURL2 as alias
		tell application "Finder" to set finderRef2 to item theAlias2
		set HiResTrash to theAlias2
		
		try
			if ((items of LoResOut) whose name ends with (".pdf")) exists then
				get every item of LoResOut whose name ends with (".pdf")
				move (every item of LoResOut whose name ends with (".pdf")) to HiResTrash with replacing
			end if
		end try
	end tell
	
	--Run PDF size comparator.
	tell application "Finder"
		set posixPath1 to ("/Users/Shared/Work/¢ Postscripts/HiRes-Trash/")
		set fileURL1 to posixPath1 as POSIX file
		set theAlias1 to fileURL1 as alias
		tell application "Finder" to set finderRef1 to item theAlias1
		set HiResTrash to theAlias1
		
		set posixPath2 to ("/Users/Shared/Work/")
		set fileURL2 to posixPath2 as POSIX file
		set theAlias2 to fileURL2 as alias
		tell application "Finder" to set finderRef2 to item theAlias2
		set workFolder to theAlias2
		
		--Find PDF files
		tell application "Finder"
			set pdfFiles to (items of HiResTrash) whose name ends with (".pdf" as list)
			set selectionList to {(pdfFiles as list)}
			set selectedCount to count items in selectionList
			
			--Compare PDF physical sizes
			set file1 to (first item of HiResTrash) whose name ends with (".pdf")
			get physical size of file1
			
			set file2 to (second item of HiResTrash) whose name ends with (".pdf")
			get physical size of file2
			
			if physical size of file1 is equal to physical size of file2 then
				display dialog "The PDF files appear to be the same size (megabytes).
		Please verify that the resolution is correct." buttons {"OK"} default button 1
				move file1 to workFolder with replacing
				move file2 to workFolder with replacing
			else
				move file1 to workFolder with replacing
				move file2 to workFolder with replacing
				
			end if
		end tell
	end tell
	
	--Delete PS files from Out folders.	
	tell application "Finder"
		set posixPath3 to ("/Users/Shared/Work/00_PDF_HI_RES/Out/")
		set fileURL3 to posixPath3 as POSIX file
		set theAlias3 to fileURL3 as alias
		tell application "Finder" to set finderRef3 to item theAlias3
		set HiResOut to theAlias3
		
		set posixPath4 to ("/Users/Shared/Work/00_PDF_LO_RES/Out/")
		set fileURL4 to posixPath4 as POSIX file
		set theAlias4 to fileURL4 as alias
		tell application "Finder" to set finderRef4 to item theAlias4
		set LoResOut to theAlias4
		
		try
			if ((items of HiResOut) whose name ends with (".ps")) exists then
				delete ((items of HiResOut) whose name ends with (".ps"))
			end if
		end try
		try
			if ((items of LoResOut) whose name ends with (".ps")) exists then
				delete ((items of LoResOut) whose name ends with (".ps"))
			end if
		end try
	end tell
end adding folder items to

Ok,

but anyway two notes

1 this code


set posixPath1 to ("/Users/Shared/Work/00_PDF_LO_RES/Out/") -- the parentheses are not needed
set fileURL1 to posixPath1 as POSIX file
set theAlias1 to fileURL1 as alias
tell application "Finder" to set finderRef1 to item theAlias1 -- the variable finderRef1 will never used
set LoResOut to theAlias1 -- this is just "renaming" the variable and also useless

can be reduced to


set posixPath1 to "/Users/Shared/Work/00_PDF_LO_RES/Out/"
set LoResOut to POSIX file posixPath1 as alias

the POSIX file “bug” can be avoided if the literal POSIX path is assigned to a variable
the Finder is not needed for these coercions!

2 this code


 try
     if ((items of LoResOut) whose name ends with (".pdf")) exists then
          get every item of LoResOut whose name ends with (".pdf")
          move (every item of LoResOut whose name ends with (".pdf")) to HiResTrash with replacing
     end if
end try

can be reduced to


(tell application "Finder")
move (every item of LoResOut whose name ends with ".pdf") to HiResTrash with replacing
(end tell)

the try block is not needed, if there is no file, nothing will be moved, no error
the if - end if block is not needed, if there is no file, nothing will be moved
“get every item of LoResOut whose name ends with (”.pdf")" is exactly the same as the part within the parentheses in the move line
calling it twice can be quite expensive

Gotcha. I’ll recode it this way.
Thank you so much for your help and instruction. I appreciate it very much!
All my best.:smiley: