Force InDesign progress bar during PDF export?

it’s a bit different - he needs to poll background task, not the file. plus he only needs to do this when using the asynchronous export file command (the export command is non-asynchronous so the next step will be only performed once the exporting is done).

as to the rest of the script - I’m sure it can be refined (there’s a lot of stuff there), but @macaria is only asking about the export part. he sure needs to isolate it and test separately until asynchronous export works.

Fixed for “asynchronous export”. But it is very-very unclear what tries to achieve the OP.

First, is need to clean up the mess with tell blocks in order to move on.

Then, the Indesign progress bar in his case will track the export of the current page, it happens quickly, the Indesign progress bar will only flicker and there will be no sense from it.

Here it makes sense to create an AppleScript progress bar that will count not the export of one page, but will count how many pages or files is exported currently. This also needs to be clarified. Does it need to count files or pages of each file? I would count the files.

Yes, you’re right – he exports single pages. whether each page exports quickly or not depends on the page - heavy pages can still take time.

So he then has to poll a list of background tasks for a particular document until they’re all completed. (The existence of a pdf file doesn’t necessarily mean that the export is done).

He can also use the list to count the number of pages exported.

Because I’m learning, my code is disorganized. I’m sorry about my inexperience since I’m a little lost on this subject. I tested this with 10 InDesign files. Your code asynchronous export PDFs works, but I’m still not seeing a progress bar.

In regards to the count question, I need to export all pages in a document as single PDFs. So if one of the files has 10 pages, then I will need 10 PDFs.

How do I then poll or target the background task?

Like I said, I don’t have Indesign. So I just have to assume that it will be something like this:
 

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 progress total steps to count theFiles
				set pagesCount to count pages of myDocument
				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
								
								repeat -- repeat until current export is finished
									try
										delay 1
										alias theFilePath
										exit repeat
									end try
								end repeat
								
							end timeout
					end tell
					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

 
NOTES:

In addition, the progress bar can count files or pages. This script will count the pages, as it seemed to me that this is what you need.

Also, if you want a standard rectangular progress bar (it’s just nicer to look at), you’ll need to use a script as an app.

1 Like

I made a few more corrections to the script (by eye). As you understand, I can’t even compile it without having InDesign.

If you want to use asynchronous export file there is some precepts:
Don’t deactivate alerts, indy needs to prepare the pages before exporting and it can take minutes for heavy pages. In this case it will display a progress window that, if you set user interaction to never, will not show.
Use the background panel facilities
Don’t use wait for task, it will disable the background panel updates.
Don’t ask for any property of the current task, it’s buggy and often empty.

In short, let InDesign do the job.
Be aware that you will not save time exporting your docs in background: it can even be slower. The only advantage is that it leaves the UI free.

tell application id "InDn"
	activate
	
	set visible of panel 37 to true -- "Background tasks"
	
	set theFile to (full name of active document) as string
	set theFile to text 1 thru -6 of theFile
	set countPages to (count pages of active document) as integer
	
	repeat with iPage from 1 to countPages
		set theDest to (theFile & " page " & iPage & ".pdf") as «class furl»
		set page range of PDF export preferences to iPage as string
		asynchronous export file active document format PDF type to theDest using (PDF export preset 6) with force save without showing options
	end repeat
	
end tell
1 Like

In theory, you need to do something like this:

set bckgdTask to asynchronous export format PDF type to theFilePath using myPDFpreset without showing options

Then use bckgdTask’s properties to poll it for completion, progress etc:

However, @ionah in his post above tells that this approach, apparently, doesn’t work as expected. I’d listen to him (unless you want to test it by yourself). I personally never used background task (I use the standard export command and build the progress and other elements in Xcode, which won’t be helpful to you anyway).

1 Like

I really like the idea of having an AppleScript progress bar. I know you don’t have InDesign, but I’m getting an error.

**Result:
error "Adobe InDesign 2023 got an error: Can’t set progress total steps to 8." number -10006 from progress total steps

Now, with the Applescript progress bar, the question arises if I need to use asynchronous export. The only reason I wanted to use asynchronous export was to have some kind of visual cue that pages were being exported.

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 ?