New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Handlers


Post Reply New Thread Subscribe

 
Thread Tools
nellbern

 
Member Since: May 30, 2008
Posts: 8
nellbern is on a distinguished road
Mac Specs: Intel 10.5.8

nellbern is offline
The script below works but I know is disastrous because I'm repeating same code. I need help to streamline (fine tune) the scrpit. Based in what I read an handler could help me to organize but i don't know how to implement it.

I want to be able to choose from 2 different types PDF presets (with layers & a composite). Based on the chosen selection then xport pdf. Also I want to chose a folder w ID files (if no ID files found then display a dialog) & want to be able select to click & select ID files on the same folder (chose file & chose folder). Missing fonts, links which will make the script stop. Then xport/ close no save.
Thank you in advance for any advise/help you can give me.

Code:
try
	with timeout of 3600 seconds --1HR
		set source_folder to choose folder with prompt "Select folder containing Indesign Documents to batch as PDF"
		tell application "Finder" to set theFiles to files of source_folder whose name extension is "indd"
		
		--Chosen  folder must be ID files. 
		if theFiles whose name extension is not "indd" then
			display alert "No 'InDesign' files to open?" giving up after 2
		end if
		
		
		set the_choice to display dialog "What PDF you need" buttons {"Quit, I change my mind", "Composite PDF", "Layer PDF"} default button 1 cancel button "Quit, I change my mind"
		
		
		
		if the button returned of the_choice is "Cancel" then
			error number -128
			beep 4
			
			--display dialog " " with icon caution buttons {"Cancel"}
			--end if
			
		else if the button returned of the_choice is "Composite PDF" then
			repeat with oneFile in theFiles
				tell application "Adobe InDesign CS4"
					set user interaction level of script preferences to never interact
					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
							--with timeout of 9999 seconds
							display dialog "Batch will Stop. Please update all MODIFIED or MISSING Links." buttons {"OK"} with icon 1 default button 1 cancel button 1 giving up after 300 --5min
							--end timeout
							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
							--with timeout of 9999 seconds
							display dialog "Batch will Stop. Please FIX Overflow Text Boxes. " buttons {"OK"} with icon 1 default button 1 cancel button 1 giving up after 300 --5min
							--end timeout
						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
							display dialog "Batch will Stop. A Font is missing." buttons {"OK"} with icon 1 default button 1 cancel button 1 giving up after 300 --5min
						end if
						
						if font_list contains "substituted" then
							
							display dialog "Batch will Stop. A Font has been substituted/missing." buttons {"OK"} with icon 1 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
						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 "PDFs" of folder source_folder) is false then
								make folder at source_folder with properties {name:"PDFs"}
							end if
						end tell
						
						tell application "Adobe InDesign CS4"
							repeat with x from 1 to count pages of myDocument
								
								set thePageName to name of page x of myDocument
								set page range of PDF export preferences to thePageName
								
								--set theFilePath to source_folder & "PDFs:" & theShortName & "_" & thePageName & ".pdf" as string
								set threeDigitPageName to text -3 thru -1 of ("00" & thePageName)
								(* text 1 thru 3 are the first 3 characters 
					text -3 thru -1 are the last 3 characters*)
								set theFilePath to source_folder & "PDFs:" & theShortName & "_" & threeDigitPageName & ".pdf" as string
								
								--EXPORT PDF
								tell myDocument
									with timeout of 600 seconds --10mins
										export format PDF type to theFilePath using "PressQuality_Crops" without showing options
										--export format PDF type to theFilePath using "PressTest" without showing options
									end timeout
								end tell
								
							end repeat
						end tell
						close myDocument saving no
						
						--========================================
						
						
						--end tell
						----------------
					end tell
					set user interaction level of script preferences to interact with all
					
				end tell
			end repeat
			
			
			
		end if
		
		
		--=================================================
		if the button returned of the_choice is "Layer PDF" then
			repeat with oneFile in theFiles
				tell application "Adobe InDesign CS4"
					set user interaction level of script preferences to never interact
					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
							--with timeout of 9999 seconds
							display dialog "Batch will Stop. Please update all MODIFIED or MISSING Links." buttons {"OK"} with icon 1 default button 1 cancel button 1 giving up after 300 --5min
							--end timeout
							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
							--with timeout of 9999 seconds
							display dialog "Batch will Stop. Please FIX Overflow Text Boxes. " buttons {"OK"} with icon 1 default button 1 cancel button 1 giving up after 300 --5min
							--end timeout
						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
							display dialog "Batch will Stop. A Font is missing." buttons {"OK"} with icon 1 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
						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 "PDFs" of folder source_folder) is false then
								make folder at source_folder with properties {name:"PDFs"}
							end if
						end tell
						
						tell application "Adobe InDesign CS4"
							repeat with x from 1 to count pages of myDocument
								
								set thePageName to name of page x of myDocument
								set page range of PDF export preferences to thePageName
								
								--set theFilePath to source_folder & "PDFs:" & theShortName & "_" & thePageName & ".pdf" as string
								set threeDigitPageName to text -3 thru -1 of ("00" & thePageName)
								(* text 1 thru 3 are the first 3 characters 
					text -3 thru -1 are the last 3 characters*)
								set theFilePath to source_folder & "PDFs:" & theShortName & "_" & threeDigitPageName & ".pdf" as string
								
								--EXPORT PDF
								tell myDocument
									with timeout of 600 seconds --10mins
										export format PDF type to theFilePath using "PressQuality_LAYERS" without showing options
										--export format PDF type to theFilePath using "PressTest" without showing options
									end timeout
								end tell
								
							end repeat
						end tell
						close myDocument saving no
						
						--========================================
						
						
						--end tell
						----------------
					end tell
					set user interaction level of script preferences to interact with all
					
				end tell
			end repeat
			
			
			
		end if
	end timeout
	
	
on error number -1712 -- the comand time out, so cancel the script
	tell application "System Events"
		tell application process "Finder"
			click button "Cancel" of window "Choose a Folder"
		end tell
	end tell
	error number -128 --throw a user cancelled error
end try

beep 5
with timeout of 10000 seconds
	tell application "Finder"
		activate
		display dialog "Check the PDFs " buttons {"OK"} with icon 1 default button 1 giving up after 15
	end tell
end timeout
QUOTE Thanks
chscag

 
chscag's Avatar
 
Member Since: Jan 23, 2008
Location: Fort Worth, Texas
Posts: 41,376
chscag has a reputation beyond reputechscag has a reputation beyond reputechscag has a reputation beyond reputechscag has a reputation beyond reputechscag has a reputation beyond reputechscag has a reputation beyond reputechscag has a reputation beyond reputechscag has a reputation beyond reputechscag has a reputation beyond reputechscag has a reputation beyond reputechscag has a reputation beyond repute
Mac Specs: 27" iMac i5, 3.2 GHz, iPad 3, iPhone 5c, 3 iPods, Yosemite

chscag is online now
Post was moved here to the proper forum. It does not belong in Community Suggestions and Feedback. Please observe forum descriptions before posting.
QUOTE Thanks
nellbern

 
Member Since: May 30, 2008
Posts: 8
nellbern is on a distinguished road
Mac Specs: Intel 10.5.8

nellbern is offline
where is this post was moved I can't find it
QUOTE Thanks
pigoo3

 
pigoo3's Avatar
 
Member Since: May 20, 2008
Location: U.S.
Posts: 28,146
pigoo3 has a reputation beyond reputepigoo3 has a reputation beyond reputepigoo3 has a reputation beyond reputepigoo3 has a reputation beyond reputepigoo3 has a reputation beyond reputepigoo3 has a reputation beyond reputepigoo3 has a reputation beyond reputepigoo3 has a reputation beyond reputepigoo3 has a reputation beyond reputepigoo3 has a reputation beyond reputepigoo3 has a reputation beyond repute
Mac Specs: 13" MB 2.4ghz, 2gig ram, OS 10.7.5

pigoo3 is offline
Quote:
Originally Posted by nellbern View Post
where is this post was moved I can't find it
Scroll up...there it is.

- Nick

- Too many "beachballs", read this: Beachballs
- Computer seems slower than it used to? Read this for some slow computer tips: Speedup
- Almost full hard drive? Some solutions. Out of Space
- Apple Battery Info. Battery
QUOTE Thanks

Post Reply New Thread Subscribe


« shell command in cocoa | Digital signature for updating Mac application »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

All times are GMT -4. The time now is 04:37 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?