Force InDesign progress bar during PDF export?

Thank you for making everything clear. Amazing information to understand some of these aspects. I think I will give up the idea of using asynchronous export as it looks like it is not going to help with what I am trying to do, and in the past I have had problems using background tasks.
I’ll try to use the AppleScript progress bar and create the pdfs using the standard export command.

This is stopping on this line

I saved the script as an app. I have not been successful in finding a solution for this. Too bad the Applescript progress bar is buggy too.

try
 

set aCount to count theFiles
tell me to set progress total steps to aCount

 

Do I need replace this part:
tell application id “com.adobe.indesign”
set progress total steps to count theFiles
set pagesCount to count pages of myDocument

with

It was my mistake. Try to replace

tell application id “com.adobe.indesign”
set progress total steps to count theFiles
set pagesCount to count pages of myDocument

with

tell application id “com.adobe.indesign”
set pagesCount to count pages of myDocument
set progress total steps to pagesCount

If this doesn’t work, try to add tell me, as well

same error
tell application “Adobe InDesign 2023”
count every page of document id 33
→ 2
set progress total steps to 2
→ error number -1708
Result: error “Adobe InDesign 2023 got an error: Can’t set progress total steps to 2.” number -10006 from progress total steps

@KniazidisR I’m using this

tell application id "com.adobe.indesign"
		set pagesCount to count pages of myDocument
		set progress total steps to pagesCount
		tell me to set progress total steps to aCount
		
		repeat with x from 1 to count pages of myDocument
			set progress description to "Page " & i & " of " & pagesCount
			set thePageName to name of page x of myDocument
			set page range of PDF export preferences to thePageName
			
			--section number must have 3 digits
			set threeDigitPageName to text -3 thru -1 of ("00" & thePageName)
			--text -3 thru -1 are the last 3 characters*)					
			set theFilePath to source_folder & "PDF:" & theShortName & "_" & threeDigitPageName & "_" & the_PROOF_choiceFav & ".pdf" as string
			
			--EXPORT PDF
			tell myDocument
				with timeout of 600 seconds --10mins
					--asynchronous export format PDF type to theFilePath using myPDFpreset without showing options --required background tasks too buggy
					export format PDF type to theFilePath using myPDFpreset without showing options
					repeat -- repeat until current export is finished
						try
							delay 1
							alias theFilePath
							exit repeat
						end try
					end repeat
				end timeout
			end tell --myDocument
			
			set progress completed steps to x
			
		end repeat --with i from 1
	end tell -- application id
	
	close myDocument saving no

 

set source_folder to choose folder with prompt "Choose a folder with InDesign documents."
tell application "Finder" to set theFiles to files of source_folder whose name extension is "indd"

--limit to only Indesign files
if (count of theFiles) is 0 then
	display dialog "No InDesign files to process" buttons "Cancel" default button "Cancel" with icon 0 giving up after 6
	return
end if

set the_choice to {"Smallest File Size", "High Quality Print", "PDF/X-1a", "Press Quality"}
set the_choiceFav to choose from list the_choice with title "PDF Job Options" with prompt "Select a PDF Job Option" default items "Flatten PDF w/o Crop marks"
if the_choiceFav is false then error number -128 (* user cancelled *)
set myPDFpreset to item 1 of the_choiceFav

-- select region
set the_PROOF_choice to {"south", "north", "west", "east", "se", "ne"}
set the_PROOF_choiceFav to choose from list the_PROOF_choice with title "Regions" with prompt "Select a region to add the name to the PDFs" default items (item 1 of the_PROOF_choice)
if the_PROOF_choiceFav is false then error number -128 -- user cancelled



repeat with oneFile in theFiles
	tell application id "com.adobe.indesign"
		
		my setUserInteractionLevel() -- no indesign messages
		activate
		
		set myDocument to open (oneFile as alias)
		tell myDocument
			
			
			--Check links +++++++++++++++++
			--if (count of ((links whose status is not normal) as list)) > 0 then  --for some reason it doesnt work with Indesign genereated QR codes
			if (count of ((links whose status contains link missing) as list)) > 0 then
				my resetUserInteractionLevel()
				--icon choices 0=stop, iocn 1=note, icon 3=caution
				display dialog "MISSING Links" buttons {"OK"} with icon 0 default button 1 cancel button 1 giving up after 300 --5min
				else if (count of ((links whose status contains link out of date) as list)) > 0 then
				my resetUserInteractionLevel()
				display dialog " MODIFIED Links." buttons {"OK"} with icon 0 default button 1 cancel button 1 giving up after 300 --5min
				--return
			end if
			
			--+++++++++++++++++
			--Check if there are any text boxes with overset text
			set thereIsTextOverflow to ((overflows of parent story of every text frame) contains true)
			if thereIsTextOverflow then
				display dialog "Overflow Text Boxes." buttons {"OK"} with icon 0 default button 1 cancel button 1 giving up after 300 --5min
			end if
			
			--++++++++++++++++++++++
			--check missing fonts
			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
			if font_list contains "not available" then
				my resetUserInteractionLevel()
				display dialog " Missing Font." buttons {"OK"} with icon 0 default button 1 cancel button 1 giving up after 300 --5min
			else if font_list contains "substituted" then
				my resetUserInteractionLevel()
				display dialog "A Font has been substituted or it is missing." buttons {"OK"} with icon 0 default button 1 cancel button 1 giving up after 300 --5min
			end if
			----============
			set source_folder to file path of myDocument
			set theName to name of myDocument
			end tell
						end tell
			
			set text item delimiters of AppleScript to {"_"}
			set theShortName to text 1 thru text item -2 of theName
			--text 1 thru text item -2 is every character from the first character to the second to last text item
			set text item delimiters of AppleScript to ""
			
			tell application "Finder"
				if (exists folder "PDF" of folder source_folder) is false then
					make folder at source_folder with properties {name:"PDF"}
				end if
			end tell
			
			
			tell application id "com.adobe.indesign"
				
				set pagesCount to count pages of myDocument
				tell me to set progress total steps to pagesCount
				repeat with x from 1 to pagesCount
					tell me to set progress description to "Page " & i & " of " & pagesCount
					set thePageName to name of page x of myDocument
					set page range of PDF export preferences to thePageName
					
					--section number must have 3 digits
					set threeDigitPageName to text -3 thru -1 of ("00" & thePageName)
					--text -3 thru -1 are the last 3 characters*)					
					set theFilePath to source_folder & "PDF:" & theShortName & "_" & threeDigitPageName & "_" & the_PROOF_choiceFav & ".pdf" as string
					
					
					
					--EXPORT PDF
					tell myDocument
						with timeout of 600 seconds --10mins
								
						               asynchronous export format PDF type to theFilePath using myPDFpreset without showing options
								
								repeat -- repeat until current export is finished
									try
										delay 1
										alias theFilePath
										exit repeat
									end try
								end repeat
								
							end timeout
					end tell
					tell me to set progress completed steps to x
					
				end repeat
			end tell
			
			close myDocument saving no
			
			my resetUserInteractionLevel()
			--====
			
	end tell
end repeat

on setUserInteractionLevel()
	tell application id "com.adobe.indesign"
						set user interaction level of script preferences to never interact
					end tell
end

on resetUserInteractionLevel()
	tell application id "com.adobe.indesign"
					set user interaction level of script preferences to interact with all
				end tell
end

 

1 Like

This is great @KniazidisR!
I deleted the asynchronous export line code because I found it problematic and slow. I used the standard export command. The progress bar works, but because it is behind Indesign and not in front, it cannot be seen. Is there any way to keep it in front while exporting PDFs?

Without your help and the other gurus, I would never have come close to finishing this.

Add

tell me to activate

before

repeat with i from 1 to pagesCount

1 Like

Once again, I needed your expertise. When I save the script as an application, I’ve noticed that files with missing or substituted fonts continue to create pdfs rather than displaying the dialog box message below and stopping. However, if I run it as a script, it will stop and display the dialogs.

Files with missing link & overset text boxes work as expected regardless of whether it is saved as a script or an application.

Do you know why this is happening ?

It all depends on what is the content of your font_list

I found this discussion in which @blend3 mentions that if a script is saved as an application then below needs to change from

if font_list contains "not available" then

to:

if font_list contains "«constant ****fsNA»" then

Otherwise, the script doesn’t work, not sure why this is, but the script gets a different type of result from the script editor than it does from an application script!
Generate Missing fonts report in Indesign - #6 by blend3

After I made the change, the application kept ignoring the missing font block and creating the PDFs rather than displaying the dialog box and stopping. As far as you know, is there any solution to this?

good advice. regardless if you’re running a script or an app you should check for both “not available” and “«constant ****fsNA»” - the result of string conversion of InDesign constants can be unpredictable.

also, I recommend to use “display alert” instead of “display dialog” when interacting with InDesign. i saw all kind of weird issues with “display dialog” being used with InDesign - from not displaying the dialog to other bugs. no issues with “display alert”.

in addition, as @KniazidisR suggested, you must check the contents of your font_list array. only then you’ll know for sure what’s going on.

The contents of the font_list variable is “substituted” and per your recommendation, I changed the dialogs to alerts. I don’t understand why it is a different result from the script vs. the application and how to fix it

image

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
        			--if font_list contains "not available" then
        			if font_list contains "«constant ****fsNA»" then
        				my resetUserInteractionLevel()
        				--display dialog " Missing Font." buttons {"OK"} with icon 0 default button 1 cancel button 1 giving up after 300 --5min
        				display alert " Missing Font." buttons {"OK"} as warning default button 1 cancel button 1 giving up after 300 --5min
        			else if font_list contains "substituted" then
        				my resetUserInteractionLevel()
        				--display dialog "A Font has been substituted or it is missing." buttons {"OK"} with icon 0 default button 1 cancel button 1 giving up after 300 --5min
        				display alert "A Font has been substituted or it is missing." buttons {"OK"} as warning default button 1 cancel button 1 giving up after 300 --5min
        				end if

just check if the status isn’t installed. anything else isn’t good.

From previous posts, I understand that your font_list does not contain strings, but InDesign constants. Therefore, the check (comparison) should be done with constants, not strings. To do this, simply remove the quotes:
 

if font_List contains not available then
	my resetUserInteractionLevel()
	display dialog " Missing Font." buttons {"OK"} with icon 0 default button 1 cancel button 1 giving up after 300 --5min
else if font_List contains substituted then
	my resetUserInteractionLevel()
	display dialog "A Font has been substituted or it is missing." buttons {"OK"} with icon 0 default button 1 cancel button 1 giving up after 300 --5min
end if

 

For days, I’ve been trying to figure this out. The script executes exactly as expected and produces no PDF if you export it as an application," open it in Script Debugger," and execute it from there with the quotes on the font_list block if statement. The display alert will appear and stop the PDF from being created. See the screengrab below.
However, if the quotes are removed from the font_list block if statement, a PDF is generated.

The other situation is that if you execute the application by double-clicking, whether or not the quotes are in the font_list block if statement, or replacing it with “«constant ****fsNA»” the PDF is still generated, which is not supposed to happen. What else can be tried so that the font_list block is not ignored by the application?

You confused me with your explanation that in some site you were offered to use ““constant ****fsNA”” and I thought that you were operating with constants, not strings. But in your script 44 you are building a font_list from strings.

The whole trick is that you can use constants in font_list and compare in the if block the constants, or you can use strings in the font_list and compare in the if block the strings. That is, the point is to compare the data of same type, and that’s it. Because if you compare data of different type (A contains B), A will never contain B, the condition will never be met and your display dialog won’t show up.

Here you have in post 44 an excessive repeat loop + an unnecessary conversion of a constant to a string (as string coercion). You can just not do all this, and operate with constants:
 

set font_list to status of every font -- constants list

if font_List contains not available then -- constant comparsion 
	my resetUserInteractionLevel()
	display dialog " Missing Font." buttons {"OK"} with icon 0 default button 1 cancel button 1 giving up after 300 --5min
else if font_List contains substituted then
	my resetUserInteractionLevel()
	display dialog "A Font has been substituted or it is missing." buttons {"OK"} with icon 0 default button 1 cancel button 1 giving up after 300 --5min
end if

 

1 Like

Thanks for your help. That worked