Importing PDF Presets

I had the following handler working

--Function to add PDF presets to Adobe InDesign
on add_pdf_presets()
	tell application "Adobe InDesign CC 2019"
		activate
		
		--Getting a list of every PDF preset & adding several if they aren't in the list already
		try
			set my_pdf_export to get the name of every PDF export preset
			--Prepress ad presets
			try
				if "Quad_Export_PDF" is not in my_pdf_export then import format PDF export presets format from alias ("Volumes:NAS:Advertising Department:16_SCRIPTS:z_PDF presets:Quad_Export_PDF.joboptions")
			on error
				tell application "Adobe InDesign CC 2019"
					activate
					display dialog "ERROR" & return & "Could not import the Quad_Export_PDF PDF preset. Please add the PDF preset manually from the NAS/Advertising Department/16_SCRIPTS/z_PDF presets/ folder and try the script again." with icon 0 giving up after 5400
				end tell
			end try
			
		end try
	end tell
end add_pdf_presets

until I added it to the larger script which has an objective c scripting addition. It works in the larger script if I take out the objective c scripting addition and breaks when I put it back in. How can I get the two to play nice? If I can get it working, there is another script that I want to add this handler to. Here’s the full code:


------------------------------------------------------------------------------------------------------------------------------
--FUNCTIONS TO FIX BUG THAT OPENS CERTAIN FILES IN A WEIRD ORDER
------------------------------------------------------------------------------------------------------------------------------

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
property filesToOpen : {}


on open droppedfiles
	
	
	set my filesToOpen to my filesToOpen & droppedfiles
	-- cancel any pending performSelector: requests
	current application's NSObject's cancelPreviousPerformRequestsWithTarget:me
	-- handle files after a short delay in case further events are received
	tell me to performSelector:"doOpen" withObject:(missing value) afterDelay:0.5
	
end open


on doOpen()
	copy my filesToOpen to droppedfiles
	set my filesToOpen to {} -- reset for next time
	
	set aRes to length of droppedfiles
	
	repeat with i in droppedfiles
		set j to POSIX path of i
	end repeat
	
	------------------------------------------------------------------------------------------------------------------------------
	------------------------------------------------------------------------------------------------------------------------------
	------------------------------------------------------------------------------------------------------------------------------
	------------------------------------------------------------------------------------------------------------------------------
	
	
	---------------------------------------------------------------------------------------------------
	--ADDING PDF PRESETS TO INDESIGN
	----------------------------------------------------------------------------------------------------	
	
	--calling the add PDF presents function at the bottom of script
	my add_pdf_presets()
	
	
	------------------------------------------------------------------------------------------------------------------------------
	--GETTING THE CURRENT YEAR OFF THE COMPUTER
	------------------------------------------------------------------------------------------------------------------------------
	
	set {year:dsYear, month:dsMonth, day:dsDay} to (current date)
	
	
	
	----------------------------------------------------------------------------------------------------
	--INTERACTING WITH THE USER
	----------------------------------------------------------------------------------------------------
	
	tell application "SystemUIServer"
		set toWhiteBox to display dialog "Do the pages for this promo have a bleed?" buttons {"Yes", "No"} giving up after 600
	end tell
	
	
	---------------------------------------------------------------------------------------------------
	--CREATING LISTS
	---------------------------------------------------------------------------------------------------
	
	set problem_list to {}
	set number_list to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
	set singleDigitNumber to {"2", "3", "4", "5", "6", "7", "8", "9"}
	set doubleDigitNumber to {"02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99"}
	
	
	
	----------------------------------------------------------------------------------------------------
	--CREATING THE PDFs SUBFOLDER IF IT DOESN'T EXIST YET
	----------------------------------------------------------------------------------------------------
	
	repeat with afile in droppedfiles
		
		--DECLARING A VARIABLE TO BE USED IN CREATING NEW FOLDERS LATER ON
		tell application "Finder" to set parent_folder to container of afile as string
		
		--CREATING PDFs FOLDER IF IT DOESN'T EXIST YET
		if not my CheckForFolder(parent_folder & "PDFs:") then
			tell application "Finder"
				make new folder at folder parent_folder with properties {name:"PDFs"}
			end tell
		end if
		
		--Creating a blank page list for each file
		set my_page_list to {}
		
		
		----------------------------------------------------------------------------------------------------
		--GETTING THE FILENAME AND EXTENSION
		----------------------------------------------------------------------------------------------------
		
		tell application "Finder"
			set fileName to get name of afile as string
			set name_ext to get name extension of afile as string
			set quark_file_types to {"qxp", "qxd"}
			set indesign_file_types to {"indd"}
			
			
			--Ensuring that the name is right even if there is no extension to chop off the file name
			if quark_file_types contains name_ext then
				set name_without_ext to (characters 1 thru -5) of fileName as string
			else if indesign_file_types contains name_ext then
				set name_without_ext to (characters 1 thru -6) of fileName as string
			else
				set name_without_ext to fileName
			end if
			
			
			---------------------------------------------------------------------------------------------------
			--DETERMINING IF THE FILE IS A QUARK OR INDESIGN FILE
			---------------------------------------------------------------------------------------------------
			
			if name_ext contains "qx" then
				set file_type to "Quark"
			else if name_ext contains "indd" or name_ext contains "idml" then
				set file_type to "InDesign"
			end if
			
			--Removing the ampersand in the filename to take care of files that are named inconsistently
			if (text 1 thru 5 of fileName as string) contains " & " then
				set search_character to " & "
				set replacement_character to "-"
				repeat 5 times
					set fileName to my replace_characters(fileName, search_character, replacement_character) -->See replace_characters function at the bottom
					if fileName does not contain "& " then exit repeat
				end repeat
			else if (text 1 thru 5 of fileName as string) contains "&" then
				set search_character to "&"
				set replacement_character to "-"
				repeat 5 times
					set fileName to my replace_characters(fileName, search_character, replacement_character) -->See replace_characters function at the bottom
					if fileName does not contain "& " then exit repeat
				end repeat
			end if
			
			--Renaming the file with the new filename that doesn't contain an ampersand
			tell application "Finder" to set name of afile to fileName
			
			--Determining if there are one or 2 pages
			if (text 1 thru 5 of fileName as string) contains "-" then
				set pdf_page_count to "2"
			else
				set pdf_page_count to "1"
			end if
			
		end tell
		
		log name_ext
		
		
		-------------------------------------------- BEGIN CODE FOR QUARK PDFS --------------------------------------------
		
		
		---------------------------------------------------------------------------------------------------
		--CREATING THE PATH TO EXPORT THE QUARK PDF INTO
		----------------------------------------------------------------------------------------------------	
		
		if name_ext contains "qx" then
			tell application "QuarkXPress 2016"
				open afile as alias --use doc prefs yes remap fonts no do auto picture import no without reflow <--Would suppress missing font dialog box but have commented that out for now because the part of the script that checks for missing fonts isn't working quite right yet
				
				tell document 1
					
					--LOOKING THROUGH IMAGES TO FIND MISSING & MODIFIED IMAGES
					set myimageprop to properties of every image
					set missing_image_list to {}
					set modified_image_list to {}
					repeat with i from 1 to the number of myimageprop
						set this_image_item to item i of myimageprop
						set myimagename to name of this_image_item as string
						set missing_status to missing of this_image_item
						set modified_status to modified of this_image_item
						set missing_image_list to missing_image_list & missing_status
						set modified_image_list to modified_image_list & modified_status
					end repeat
					
					--LOOKING TO FIND OVERFLOWS ON TEXT BOXES
					set boxOverflowList to {}
					repeat with i from 1 to the number of text box
						set thisTextBox to text box i
						if box overflows of thisTextBox is true then
							set boxOverflowList to "Overflow"
						end if
					end repeat
					
					
					----------------------------------------------------------------------------------------------------
					--SETTING PATHS TO THE PDF FOLDER & ERROR FOLDER BEFORE MAKING PDF
					----------------------------------------------------------------------------------------------------
					
					--DECLARING VARIABLES TO GET PATHS TO DOCUMENT & SUBFOLDERS
					set parent_folder_PDF to parent_folder & "PDFs" as string
					set parent_folder_Error to parent_folder_PDF & ":" & "1_Check for Images and Text Box Overflows:" as string
					
					
					--Repeating making individual page pdfs
					set quark_pages to every page
					set quark_count to length of quark_pages
					repeat with a_page in quark_pages
						set orig_page_number to get name of a_page
						
						
						--Making the page number 2 digits if it is only one digit
						if (orig_page_number as string) is in number_list then
							set page_number to "0" & orig_page_number
						else
							set page_number to orig_page_number
						end if
						
						
						--Making pdf if the current page number is not more than 1 or 2.
						--Preventing 2, 3, 4, 5, 6 unnecessary pages from being pdf'd.
						if (orig_page_number as string) is not greater than pdf_page_count then
							
							
							--Stringing together the full path to export the pdf into
							set pdf_path to parent_folder_PDF & ":" & name_without_ext & " (Page " & page_number & ").pdf"
							set pdf_error_path to parent_folder_Error & name_without_ext & " (Page " & page_number & ").pdf"
							
							
							
							----------------------------------------------------------------------------------------------------
							--PUTTING PDF IN ERROR SUBFOLDER IF FONTS ARE MISSING OR IMAGES ARE Missing or Modified
							----------------------------------------------------------------------------------------------------	
							
							if missing_image_list contains true or modified_image_list contains true or boxOverflowList contains "Overflow" then
								if not my CheckForFolder(parent_folder_Error) then
									tell application "Finder"
										make new folder at folder parent_folder_PDF with properties {name:"1_Check for Images and Text Box Overflows"}
									end tell
								end if
								try
									export in pdf_error_path as "PDF" page range orig_page_number PDF output style "Quad_Export_PDF"
									
									--Overwriting if the pdf file already exists
								on error
									tell application "Finder"
										if exists file (pdf_error_path as alias) then
											set pdf_file1 to pdf_error_path as alias
											delete file pdf_file1
											tell application "QuarkXPress 2016"
												tell document 1
													export in pdf_error_path as "PDF" page range orig_page_number PDF output style "Quad_Export_PDF"
												end tell
											end tell
											
										end if
									end tell
								end try
								
								
								----------------------------------------------------------------------------------------------------
								--PUTTING PDF IN REGULAR PDFs FOLDER IF EVERYTHING IS GOOD	
								----------------------------------------------------------------------------------------------------	
								
							else
								try
									export in pdf_path as "PDF" page range orig_page_number PDF output style "Quad_Export_PDF" with replacing
								on error
									tell application "Finder"
										if exists file (pdf_path as alias) then
											set pdf_file1 to pdf_path as alias
											delete file pdf_file1
											tell application "QuarkXPress 2016"
												tell document 1
													export in pdf_path as "PDF" page range orig_page_number PDF output style "Quad_Export_PDF"
												end tell
											end tell
											
										end if
									end tell
								end try
							end if
						end if
						
					end repeat
					
					
					----------------------------------------------------------------------------------------------------
					--CLOSING THE DOCUMENT IF EVERYTHING IS OKAY
					--------------------------------------------------------------------------------------------------
					
					if missing_image_list does not contain true or modified_image_list does not contain true or boxOverflowList does not contain "Overflow" then
						close saving no
					end if
					
					---------------------------------------------------------------------------------------------------
					---------------------------------------------------------------------------------------------------		
					
				end tell
			end tell
		end if
		
		
		---------------------------------------------- END CODE FOR QUARK PDFS ---------------------------------------------
		
		
		
		-------------------------------------------- BEGIN CODE FOR INDESIGN PDFS ------------------------------------------
		
		
		------------------------------------------------------------------------------------------------------------------------------
		-- CONVERTING LEGACY IDML FILES TO INDESIGN FILES
		------------------------------------------------------------------------------------------------------------------------------
		
		if name_ext contains "idml" or name_ext contains "indd" then
			--Attempting to open the file in InDesign
			tell application "Adobe InDesign CC 2019"
				activate
				
				
				--Getting rid of annoying missing image/font popup dialogs
				set user interaction level of script preferences to never interact
				
				
				
				try
					open afile as alias
					
					--Displaying an error message and quitting the script if the file was created by a newer version of InDesign
				on error
					display dialog "File " & fileName & " is too new to be opened by this version of InDesign." with icon stop giving up after 5400
					--set too_new_list to too_new_list & "• " & fileName & return
				end try
				
				
				
				--if too_new_list does not contain filename then
				--if file_ext contains ".idml" then
				
				--Renaming .idml files as .indd files
				tell application "Finder"
					activate
					set oldDelims to AppleScript's text item delimiters
					
					set dot_extension to "." & name_ext as string
					set AppleScript's text item delimiters to dot_extension
					set fileName to name of afile --> ex. Disneyland.tif
					set nameWithoutExtension to first text item of fileName --> Disneyland
					set newName to nameWithoutExtension & ".indd" --> Disneyland_s_4c.tif
					
					--TELLING THE COMPUTER THAT THE FOLDER WE'RE ABOUT TO MOVE IS THE NEWLY NAMED ONE
					--The original dropped file no longer exists as far as the computer is concerned because we changed the filename
					set parentFolder to container of afile as string
					set filePath to parentFolder & newName as string
					
					--RESETTING APPLESCRIPT'S TEXT ITEM DELIMITERS
					set AppleScript's text item delimiters to oldDelims
					
				end tell
				
				
				--Saving the idml file as an InDesign file
				tell active document to save to file filePath
				close active document saving no
				
				
				--Setting afile to the InDesign file
				set afile to filePath as alias
				
				
				---------------------------------------------------------------------------------------------------
				--SETTING PREFERENCES IN INDESIGN
				----------------------------------------------------------------------------------------------------	
				
				set user interaction level of script preferences to never interact -->Prevents InDesign from popping up warnings that interrupt the script. Instead, I added code that puts documents with problems in a separate folder.
				
				tell view preferences
					set horizontal measurement units to inches
					set vertical measurement units to inches
				end tell
				
				
				------------------------------------------------------------------------------------------------------------------------------
				-- CREATING SEPARATE NEW LAYER FOR THE MEASURING ADS SCRIPT
				------------------------------------------------------------------------------------------------------------------------------	
				
				--THIS WAY THE TEXT FRAMES TO MEASURE CAN BE DRAWN ON A SEPARATE LAYER AND THE COMPUTER CAN MEASURE ALL FRAMES ON THAT LAYER 
				--WITHOUT ACCIDENTALLY MEASURING TEXT FRAMES THAT IT SHOULDN'T MEASURE
				
				open afile
				
				tell active document
					
					
					try
						set measuringLayer to make layer with properties {name:"Measure"}
						
						--Telling script to use existing measure layer if it already exists
					on error
						
						set measuringLayer to layer "Measure"
					end try
					
					
					
					
					----------------------------------------------------------------------------------------------------
					--CHECKING FOR Missing or Modified IMAGES & MISSING FONTS & TEXT BOX OVERFLOWS
					----------------------------------------------------------------------------------------------------	
					
					--LOOKING THROUGH EVERY FONT TO SEE IF ANY ARE MISSING
					set myfontprop to properties of every font
					set font_list to {}
					repeat with i from 1 to the number of myfontprop
						set this_font_item to item i of myfontprop
						set myfontname to name of this_font_item as string
						set fontstatus to status of this_font_item as string
						set font_list to font_list & fontstatus
					end repeat
					
					
					--LOOKING THROUGH EVERY IMAGE IN THE FILE TO SEE IF ANY ARE MISSING/MODIFIED
					set mylinkprop to properties of every link
					set link_list to {}
					repeat with i from 1 to the number of mylinkprop
						set this_link_item to item i of mylinkprop
						set mylinkname to name of this_link_item as string
						set linkstatus to status of this_link_item as string
						set link_list to link_list & linkstatus
					end repeat
					
					
					--------------------------------------------------------------------------------------------------------------
					-- ELIMINATING TEXT BOX OVERFLOWS
					--------------------------------------------------------------------------------------------------------------						
					
					set pdf_page_list to {}
					
					--Repeating with each page
					set myPages to every page
					repeat with myPage in myPages
						tell myPage
							set myBoxes to every rectangle
							set myBoxCount to count of myBoxes
							if myBoxCount is greater than 0 then
								set pdf_page_list to pdf_page_list & name of myPage
							end if
							
							set myGroups to every group
							set myGroupCount to count of myGroups
							if myGroupCount is greater than 0 then
								if myPage is not in pdf_page_list then
									set pdf_page_list to pdf_page_list & name of myPage
								end if
							end if
							
							set my_text_boxes to every text frame
							set text_box_count to count of my_text_boxes
							repeat with my_text_box in my_text_boxes
								try
									if overflows of myBox then
										fit my_text_box given frame to content
									end if
								end try
							end repeat
							if myPage is not in pdf_page_list and text_box_count is greater than 0 then
								set pdf_page_list to pdf_page_list & name of myPage
							end if
						end tell
					end repeat
				end tell
				
				
				
				--Saving the text box overflow fix
				tell document 1 to save
				
				
				----------------------------------------------------------------------------------------------------
				--SETTING PATHS TO THE PDF FOLDER & ERROR FOLDER BEFORE MAKING PDF
				----------------------------------------------------------------------------------------------------
				
				--DECLARING VARIABLES TO GET PATHS TO DOCUMENT & SUBFOLDERS
				set parent_folder_PDF to parent_folder & "PDFs" as string
				set parent_folder_Error to parent_folder_PDF & ":" & "1_Check for Images and Text Box Overflows:" as string
				
				
				tell active document to set my_page_list to my_page_list & (get the name of every page)
				
				
				repeat with this_page in my_page_list
					
					if (this_page as string) is in pdf_page_list then
						set my_page_range to this_page as string
						
						
						--SETTING THE PAGE RANGE SO EACH PAGE IS EXPORTED INDIVIDUALLY
						tell PDF export preferences
							set page range to my_page_range
						end tell
						
						
						--Getting the page number for the current page
						set page_number_orig to this_page
						if page_number_orig is in number_list then
							set page_number to "0" & page_number_orig as string
						else
							set page_number to page_number_orig
						end if
						
						
						if (page_number_orig as string) is not greater than pdf_page_count then
							
							--Stringing together the full path to export the PDF into
							set pdf_path to parent_folder_PDF & ":" & name_without_ext & " (Page " & page_number & ").pdf"
							set pdf_error_path to parent_folder_Error & name_without_ext & " (Page " & page_number & ").pdf"
							
							
							----------------------------------------------------------------------------------------------------
							--ADDING WHITE BOXES TO AVOID CLUTTER ON BLEED EDGES (IF USER SELECTED NO TO FIRST PROMPT)
							----------------------------------------------------------------------------------------------------	
							
							--Using the front layer, unless that is the measure layer or FPO layer, then using the next layer
							tell active document
								set (locked of every layer whose name does not contain "FPO" and name does not contain "Measure") to false -->this makes sure the layer with the text/art isn't locked
								if locked of front layer is false then
									set front_layer to front layer
								else
									set the_layers to every layer
									repeat with a_layer in the_layers
										if locked of a_layer is false then
											set front_layer to a_layer
										end if
									end repeat
								end if
								
								--Getting the front layer's name
								set layer_name to name of front_layer
								
							end tell
							
							
							
							if button returned of toWhiteBox contains "No" then
								
								
								--Making white boxes when making pdf for page 1
								if (pdf_page_count as string) is "2" and (page_number_orig as string) is "1" then
									
									
									tell document 1
										--try
										
										
										tell page 2 of spread 1
											
											set pageWidth to item 4 of bounds
											set pageHeight to item 3 of bounds
											set pageLeftSide to item 2 of bounds
											
											--Bounds are the coordinates of each side of a page or box. {top side, left side, bottom side, right side}. 
											--So, if a page was 8.5"x11", it's bounds would be {"0", "0", "11", "8.5"} or {item 1, item 2, item 3, item 4}. 
											--Usually the width is item 4 minus item 2 (the coordinates of the right side minus the coordinates of the left side). Since the left side is 0, the width is equal to item 4. 
											--This is why I was able to set the pageWidth to item 4 of bounds. The same logic applies for the pageHeight.
											set newTextFrame1 to make new text frame at beginning with properties {layer:front_layer, geometric bounds:{"0", pageLeftSide, pageHeight, pageWidth}, fill color:"Paper", label:"TempFrame1"}
										end tell
										
										
										tell page 1
											
											--CREATING A 2 INCH WIDE BOX THAT WILL BE JUST OFF TO THE LEFT SIDE OF THE PAGE
											set newTextFrameEdge1 to make new text frame at beginning with properties {layer:front_layer, geometric bounds:{"0", "-2", pageHeight, "0"}, fill color:"Paper", label:"TempFrame1"} --creating 2 inch wide box off to the left side
										end tell
										
										--end try
									end tell
									
									-------------------------------
									
									--Making white boxes when making pdf for page 2
								else if (pdf_page_count as string) is "2" and (page_number_orig as string) is "2" then
									
									tell active document
										delete (every text frame whose label is "TempFrame1")
									end tell
									
									
									--MAKING WHITE BOX OVER PAGE 1 BEFORE CREATING PDF OF PAGE 2
									tell document 1
										tell page 1
											
											--Bounds are the coordinates of each side of a page or box. {top side, left side, bottom side, right side}. 
											--So, if a page was 8.5"x11", it's bounds would be {"0", "0", "11", "8.5"} or {item 1, item 2, item 3, item 4}. 
											--Usually the width is item 4 - item 2 (the coordinates of the right side minus the coordinates of the left side). Since the left side is 0, the width is equal to item 4. 
											--This is why I was able to set the pageWidth to item 4 of bounds. The same logic applies for the pageHeight (item 3 - item 1). Item 1 is 0, page height is equal to item 3.
											set pageWidth to item 4 of bounds
											set pageHeight to item 3 of bounds
											set pageLeftSide to item 2 of bounds
											set newTextFrame2 to make new text frame at beginning of the front layer with properties {layer:front_layer, geometric bounds:{"0", pageLeftSide, pageHeight, pageWidth}, fill color:"Paper", label:"TempFrame2"}
										end tell
										
										
										try
											tell page 2
												
												set pageWidth2 to item 4 of bounds
												set pageWidth2Offset to (pageWidth2 + 2)
												--CREATING A 2 INCH WIDE BOX THAT WILL BE JUST OFF TO THE LEFT SIDE OF THE PAGE
												set newTextFrameEdge2 to make new text frame at beginning with properties {layer:front_layer, geometric bounds:{"0", pageWidth2, pageHeight, (pageWidth2 + "2")}, fill color:"Paper", label:"TempFrame2"} --creating 2 inch wide box off to the left side
												--set origin of bounds of newBoxEdge to {0 + 0, -2} --moving the 2 inch wide box off to the left side
											end tell
										end try
									end tell
									
								end if
							end if
							
							
							----------------------------------------------------------------------------------------------------
							--PUTTING PDF IN ERROR SUBFOLDER IF FONTS ARE MISSING OR IMAGES ARE Missing or Modified
							----------------------------------------------------------------------------------------------------	
							
							tell active document
								
								if font_list contains "«constant ****fsSu»" or font_list contains "missing" or link_list contains "«constant ****lmis»" or link_list contains "«constant ****lood»" or link_list contains "missing" or link_list contains "modified" then -->Note: «constant ****lmis» means image is missing, «constant ****lood» means image is  modified, «constant ****fsSu» means the font is missing.
									
									if not my CheckForFolder(parent_folder_Error) then
										tell application "Finder"
											make new folder at folder parent_folder_PDF with properties {name:"1_Check for Images and Text Box Overflows"}
										end tell
									end if
									try
										export format PDF type to pdf_error_path using "Quad_Export_PDF" without showing options
										
										
										--Overwriting if the pdf file already exists
									on error
										tell application "Finder"
											if exists file (pdf_error_path as alias) then
												set pdf_file1 to pdf_error_path as alias
												delete file pdf_file1
												tell application id "com.adobe.indesign"
													tell document 1
														export format PDF type to pdf_error_path using "Quad_Export_PDF" without showing options
													end tell
												end tell
												
											end if
										end tell
									end try
									
									
									
									----------------------------------------------------------------------------------------------------
									--PUTTING PDF IN REGULAR PDFs FOLDER IF EVERYTHING IS GOOD	
									----------------------------------------------------------------------------------------------------	
									
								else
									
									try
										export format PDF type to pdf_path using "Quad_Export_PDF" without showing options
										
									on error
										tell application "Finder"
											if exists file (pdf_path as alias) then
												set pdf_file1 to pdf_path as alias
												delete file pdf_file1
												tell application id "com.adobe.indesign"
													tell document 1
														export format PDF type to pdf_path using "Quad_Export_PDF" without showing options
													end tell
												end tell
												
											end if
										end tell
									end try
								end if
							end tell
						end if
					end if
					
					
					----------------------------------------------------------------------------------------------------
					--REMOVING THE WHITE BOX ON PAGE 1 AFTER ALL PDFS ARE MADE
					----------------------------------------------------------------------------------------------------	
					
					if button returned of toWhiteBox contains "No" then
						
						if pdf_page_count is "2" then
							
							try
								tell active document to delete (every text frame whose label is "TempFrame2")
							end try
							
						end if
					end if
					
				end repeat
				
				
				
				------------------------------------------------------------------------------------------------------------------------------
				-- RESETTING PREFERENCES
				------------------------------------------------------------------------------------------------------------------------------					
				
				--RESETTING THE PDF EXPORT PREFERENCES
				tell PDF export preferences to set page range to all pages
				
				--RESETTING THE DIALOG BOXES/WARNINGS SO THEY ARE NO LONGER SUPPRESSED
				set user interaction level of script preferences to interact with all
				
				
				
				----------------------------------------------------------------------------------------------------
				--CLOSING THE DOCUMENT IF EVERYTHING IS OKAY
				----------------------------------------------------------------------------------------------------
				
				-- Say farewell, so long to that document... and onto the next dropped document. 
				
				close active document saving no
				
				
				
			end tell
		end if
	end repeat
	
	
	----------------------------------------------------------------------------------------------------
	--RESETTING PREFERENCES
	----------------------------------------------------------------------------------------------------
	
	--Getting rid of annoying missing image/font popup dialogs
	tell application "Adobe InDesign CC 2019" to set user interaction level of script preferences to never interact
	
	
	
	---------------------------------------------------------------------------------------------------
	--OPENING THE FOLDER WITH THE PDF FILE(S)
	---------------------------------------------------------------------------------------------------
	
	tell application "Finder"
		open parent_folder_PDF as alias
		set POSIX_parent_folder_PDF to POSIX path of parent_folder_PDF as string
	end tell
	
	
	---------------------------------------------------------------------------------------------------
	--DISPLAYING A SUCCESS OR PROBLEM DIALOG TO THE USER
	---------------------------------------------------------------------------------------------------
	
	if problem_list is {} then
		
		
		--Displaying a SUCCESS dialog
		tell application "SystemUIServer" to display dialog "SUCCESS!!" & return & "PDF files have been made for " & name_without_ext & "." with icon note giving up after 5400
		
		
		--Creating the success email
		set myHD to path to startup disk as «constant XMLtTEXT»
		if myHD contains "Melissa_B" then
			set mySignature to "<b>" & "Melissa Bornbach" & "</font> </b>" & "<br>" & "Pre-Press Technician" & "<br>" & "Blain Supply, Inc." & "<br>" & "mbornbach@blainsupply.com"
		else
			set mySignature to "<b>" & "Paul Leverson" & "</font> </b>" & "<br>" & "Pre-Press Manager" & "<br>" & "Blain Supply, Inc." & "<br>" & "pleverson@blainsupply.com"
		end if
		
		set subject_name to folder_name & " Ready"
		set content_info to "The " & name_without_ext & " promotion has been pdf'd for Quad in the following folder:" & "<br>" & "• " & POSIX_parent_folder_PDF & "<br><br>" & mySignature
		my send_email(subject_name, content_info, myHD)
		
		
		
		
		--Displaying a SORRY dialog
	else
		tell application "SystemUIServer" to display dialog "SORRY" & return & "The following files did not create pdfs: " & return & return & problem_list & return & return & " If you tried making the pdf file(s) while on the server, please try again from your desktop." with icon caution giving up after 5400
	end if
	
	
	
end doOpen

on quit
	continue quit
end quit



----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
--FUNCTIONS
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------

--FUNCTION TO GET PATH TO PARENT FOLDER OF QUARK DOCUMENT
on get_parent_folder(filePath)
	set folderParts to my GetTextItem(filePath as text, ":", {1, -2})
	set oldDelims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {":"}
	set parent_folder to folderParts as text
	set AppleScript's text item delimiters to oldDelims
	
	return (parent_folder & ":") as text
end get_parent_folder

------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------

--FUNCTION TO CHECK IF A FOLDER EXISTS
on CheckForFolder(thisFolder)
	tell application "Finder"
		return (exists folder thisFolder)
	end tell
end CheckForFolder

------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------

--FUNCTION TO GET PATH TO DOCUMENT AS A TEXT ITEM (USED IN THE getparent_folder Function above)
on GetTextItem(ThisString, ThisDelim, ThisItem)
	-- ThisString -> String to look in
	-- ThisDelim -> Text element that delimit the string
	-- ThisItem -> Number of the element to return
	copy the text item delimiters to oldDelims
	set the text item delimiters to ThisDelim
	set arrItem to every text item of ThisString
	
	
	if class of ThisItem is list then
		set FromItem to item 1 of ThisItem
		set ToItem to item 2 of ThisItem
		set TheReturn to (items FromItem thru ToItem of arrItem) as text
	else
		if ThisItem ≠ 0 then
			set TheReturn to (item ThisItem of arrItem) as text
		else
			set TheReturn to arrItem -- return every items
		end if
	end if
	set the text item delimiters to oldDelims
	return TheReturn
end GetTextItem

----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------

--SEND EMAIL FUNCTION
on send_email(the_subject, the_content, the_HD)
	
	--Getting today's date
	set {year:dsYear, month:dsMonth, day:dsDay, weekday:week_day} to (current date)
	--set dsMonth to dsMonth as string
	--set dsDay to dsDay as string
	
	
	--Creating the email
	tell application "Mail"
		activate
		
		
		set newMessage to make new «class outm» with properties {subject:the_subject, content:the_content}
		if the_HD contains "Melissa_B" then
			make new cc recipient at newMessage with properties {email addresses:{name:"Melissa Bornbach", address:"mbornbach@blainsupply.com"}}
		else
			make new cc recipient at newMessage with properties {email addresses:{name:"Paul Leverson", address:"pleverson@blainsupply.com"}}
		end if
		
		--make new attachment at newMessage1 with properties {file:the_file} --ATTACHING EACH GENERATED PDF
		open newMessage
		--send newMessage
		
		
	end tell
end send_email


------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------

--FUNCTION TO REPLACE CHARACTERS
on replace_characters(the_phrase, search_string, replacement_string)
	--Changing illegal xml characters to ones xml can understand
	
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to search_string
	--set item_count to count of text items of the_phrase
	set text_items to text items of the_phrase
	set AppleScript's text item delimiters to replacement_string
	set the_phrase to text_items as Unicode text
	set AppleScript's text item delimiters to tid
	log the_phrase
	
	return the_phrase
end replace_characters

------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------


--Function to add PDF presets to Adobe InDesign
on add_pdf_presets()
	tell application "Adobe InDesign CC 2019"
		activate
		
		--Getting a list of every PDF preset & adding several if they aren't in the list already
		try
			set my_pdf_export to get the name of every PDF export preset
			display dialog my_pdf_export as string
			--Prepress ad presets
			try
				if "Quad_Export_PDF" is not in my_pdf_export then import format PDF export presets format from alias ("Volumes:NAS:Advertising Department:16_SCRIPTS:z_PDF presets:Quad_Export_PDF.joboptions")
			on error
				tell application "Adobe InDesign CC 2019"
					activate
					display dialog "ERROR" & return & "Could not import the Quad_Export_PDF PDF preset. Please add the PDF preset manually from the NAS/Advertising Department/16_SCRIPTS/z_PDF presets/ folder and try the script again." with icon 0 giving up after 5400
				end tell
			end try
			
		end try
	end tell
end add_pdf_presets

What scripting addition?

This section at the top and bottom of the code.

------------------------------------------------------------------------------------------------------------------------------
--FUNCTIONS TO FIX BUG THAT OPENS CERTAIN FILES IN A WEIRD ORDER
------------------------------------------------------------------------------------------------------------------------------

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
property filesToOpen : {}


on open droppedfiles
	
	
	set my filesToOpen to my filesToOpen & droppedfiles
	-- cancel any pending performSelector: requests
	current application's NSObject's cancelPreviousPerformRequestsWithTarget:me
	-- handle files after a short delay in case further events are received
	tell me to performSelector:"doOpen" withObject:(missing value) afterDelay:0.5
	
end open


on doOpen()
	copy my filesToOpen to droppedfiles
	set my filesToOpen to {} -- reset for next time
	
	set aRes to length of droppedfiles
	
	repeat with i in droppedfiles
		set j to POSIX path of i
	end repeat
	
	
	--rest of code
	
	
end doOpen

on quit
	continue quit
end quit

Ah, you mean you’ve added some AppleScriptObjC code. OK.

One of the things that does is change, slightly, the way AppleScript handles file and alias specifiers. The workaround is simple. Where you have this:

               if "Quad_Export_PDF" is not in my_pdf_export then import format PDF export presets format from alias ("Volumes:NAS:Advertising Department:16_SCRIPTS:z_PDF presets:Quad_Export_PDF.joboptions")

You need to change it to this:

               if "Quad_Export_PDF" is not in my_pdf_export then import format PDF export presets format from ("Volumes:NAS:Advertising Department:16_SCRIPTS:z_PDF presets:Quad_Export_PDF.joboptions" as alias)

Thank you so much!!! :slight_smile: