Report Generation Problem

Dear All,

Please see the code below, I want to generate reports of missing images & missing fonts. Code is working very fine, but reports are not getting generated.

Please help me, it is very very urgent.


set source_folder to choose folder with prompt "Select folder containing InDesign Documents"
tell application "Finder" to set item_list to every item of source_folder
repeat with this_item in item_list
	set doc_kind to get kind of this_item
	if doc_kind contains "Indesign" then
		tell application "Adobe InDesign CS2"
			set user interaction level of script preferences to never interact
			open this_item
			set DocName to the name of document 1
			tell document 1
				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 error_report(source_folder, DocName)
					--				else
					--					close document 1 saving no
				end if
				try
					set ImgNames to (name of every link whose needed is true and status is link missing)
					if class of ImgNames is not list then set ImgNames to {ImgNames}
					set badImgCounter to count of ImgNames
					repeat with i from 1 to badImgCounter
						my write_Report(DocName, ImgNames, source_folder)
					end repeat
				end try
			end tell
			close document 1 saving no
		end tell
	end if
end repeat

on error_report(source_folder, DocName)
	tell application "Finder"
		try
			set error_folder to (source_folder as string) & DocName & "_ErrorFolder" as alias
		on error
			tell application "Finder"
				make new folder at source_folder with properties {name:DocName & "_ErrorFolder"}
				set error_folder to (source_folder as string) & DocName & "_ErrorFolder" as alias
			end tell
		end try
	end tell
	tell application "Adobe InDesign CS2"
		tell document 1
			package to error_folder copying fonts no copying linked graphics no copying profiles no updating graphics no ignore preflight errors no creating report yes including hidden layers no
			--			close saving no
		end tell
	end tell
	tell application "Finder"
		try
			set text_file to (error_folder as string) & "Instruction.txt" as alias
			set the name of text_file to DocName & ".txt"
		end try
	end tell
end error_report
on write_Report(DocName, ImgNames, source_folder)
	set The_Report to source_folder & DocName & "“Missing Images.txt"
	try
		open for access file the The_Report with write permission
		write ImgNames to file the The_Report starting at eof
		close access file the The_Report
	on error
		close access file the The_Report
	end try
end write_Report

Thanks & Regards

Hi,

the problem is, source_folder is an alias, so the result of this line

set The_Report to source_folder & DocName & "“Missing Images.txt" 

is a list containing an alias and two strings.
Change the line to

set The_Report to source_folder as text & DocName & "“Missing Images.txt" 

btw: the syntax of the write routine should look like this, it’s recommended to use a file descriptor (variable ff)


on write_Report(DocName, ImgNames, source_folder)
	set The_Report to (source_folder as text) & DocName & "“Missing Images.txt"
	try
		set ff to open for access file The_Report with write permission
		write ImgNames to ff starting at eof
		close access ff
	on error
		close access file The_Report
	end try
end write_Report

Hi Stefen,

Thanks for the support. Now it is generating the Missing Image report. But another report Instruction.txt is not getting generated. See the code below:

on error_report(source_folder, DocName)
	tell application "Finder"
		try
			set error_folder to (source_folder as string) & DocName & "_ErrorFolder" as alias
		on error
			tell application "Finder"
				make new folder at source_folder with properties {name:DocName & "_ErrorFolder"}
				set error_folder to (source_folder as string) & DocName & "_ErrorFolder" as alias
			end tell
		end try
	end tell
	tell application "Adobe InDesign CS2"
		tell document 1
			package to error_folder copying fonts no copying linked graphics no copying profiles no updating graphics no ignore preflight errors no creating report yes including hidden layers no
			--			close saving no
		end tell
	end tell
	tell application "Finder"
		try
			set text_file to (error_folder as string) & "Instruction.txt" as alias
			set the name of text_file to DocName & ".txt"
		end try
	end tell
end error_report

Also, I have another problem of Missing Images Report, it is generating something like:

But I want like this:

Thanks & Regards,

you’re going to write a list to the text file,
but you want paragraphs.

Replace

.
	try
		set ImgNames to (name of every link whose needed is true and status is link missing)
		if class of ImgNames is not list then set ImgNames to {ImgNames}
		set badImgCounter to count of ImgNames
		repeat with i from 1 to badImgCounter
			my write_Report(DocName, ImgNames, source_folder)
		end repeat
	end try
.

with

.
	try
		set ImgNames to (name of every link whose needed is true and status is link missing)
		if (count ImgNames) is not 0 then
			set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
			set ImgNames to ImgNames as text
			set AppleScript's text item delimiters to ASTID
			my write_Report(DocName, ImgNames, source_folder)
		end if
	end try
.

Hi Stefen,

Images report is ok, but Fonts report is not getting generated. Do you have any idea for it.

Thanks

it’s the same problem, you have to flatten the list

Hi Stefen,

See the below code I am trying to

	tell application "Adobe InDesign CS2"
		tell document 1
			package to error_folder copying fonts no copying linked graphics no copying profiles no updating graphics no ignore preflight errors no creating report yes including hidden layers no
			--			close saving no
		end tell

create a package with copying fonts.

Any idea.

Thanks

Hi Stefen,

This is the complete code below:


on error_report(source_folder, DocName)
	tell application "Finder"
		try
			set error_folder to (source_folder as string) & DocName & "_ErrorFolder" as alias
		on error
			tell application "Finder"
				make new folder at source_folder with properties {name:DocName & "_ErrorFolder"}
				set error_folder to (source_folder as string) & DocName & "_ErrorFolder" as alias
			end tell
		end try
	end tell
	tell application "Adobe InDesign CS2"
		tell document 1
			package to error_folder copying fonts no copying linked graphics no copying profiles no updating graphics no ignore preflight errors no creating report yes including hidden layers no
			--			close saving no
		end tell
	end tell
	tell application "Finder"
		try
			set text_file to (error_folder as string) & "Instruction.txt" as alias
			set the name of text_file to DocName & ".txt"
		end try
	end tell
end error_report

It is creating the folder but not generating the text file.
Thanks

This cannot work, coercing a string path to an alias throws an error, if the path doesn’t exist.
The try block ignores silently the error.
For debugging scripts it’s recommended to comment out all try blocks to see the errors

on error_report(source_folder, DocName)
	tell application "Finder"
		try
			set error_folder to (source_folder as string) & DocName & "_ErrorFolder" as alias
		on error
			set error_folder to (make new folder at source_folder with properties {name:DocName & "_ErrorFolder"}) as alias
		end try
	end tell
	tell application "Adobe InDesign CS2"
		tell document 1
			package to error_folder copying fonts no copying linked graphics no copying profiles no updating graphics no ignore preflight errors no creating report yes including hidden layers no
			--	close saving no
		end tell
	end tell
	set text_file to (error_folder as text) & DocName & ".txt"
end error_report

Hi Stefen,

I tested with the below code:

on error_report(source_folder, DocName)
	tell application "Finder"
		--try
		set error_folder to (source_folder as string) & DocName & "_ErrorFolder" as alias
		--on error
		--	set error_folder to (make new folder at source_folder with properties {name:DocName & "_ErrorFolder"}) as alias
		--end try
	end tell
	tell application "Adobe InDesign CS2"
		tell document 1
			package to error_folder copying fonts no copying linked graphics no copying profiles no updating graphics no ignore preflight errors no creating report yes including hidden layers no
			--    close saving no
		end tell
	end tell
	set text_file to (error_folder as text) & DocName & ".txt"
end error_report

And the error is:

I also removed the code as alias, and after removing this code folder is not getting created. Only Images report is getting generated.

Thanks

leave the try block in the Finder tell block untouched, because this is a controlled forced error.
The folder will be created only, if the folder doesn’t exist and therefore the error occurs

I Got the problem area, actually, I am trying to

	tell application "Finder"
		--try
		set text_file to (error_folder as string) & "Instruction.txt" as alias
		set the name of text_file to DocName & ".txt"
		--end try
	end tell

But no file is getting generated in the folder. I think Package creation code is the main problem.

Thanks

I can’t prove it, I get an compile error with CS3 in the package to error_folder line,
because there is no parameter including hidden layers in the dictionary

But with CS2 it is required. I tried without this, and throwing error of missing parameter of including hidden layers options.

Thanks

Hi

I checked with the below code:


set source_folder to choose folder with prompt "Select folder containing InDesign Documents"
tell application "Finder" to set item_list to every item of source_folder
repeat with this_item in item_list
	set doc_kind to get kind of this_item
	if doc_kind contains "Indesign" then
		tell application "Adobe InDesign CS2"
			set user interaction level of script preferences to never interact
			open this_item
			set DocName to the name of document 1
			tell document 1
				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 error_report(source_folder, DocName)
				else
					close document 1 saving no
				end if
			end tell
		end tell
	end if
end repeat

on error_report(source_folder, DocName)
	tell application "Finder"
		try
			set error_folder to (source_folder as string) & DocName & "_ErrorFolder" as alias
		on error
			tell application "Finder"
				make new folder at source_folder with properties {name:DocName & "_ErrorFolder"}
				set error_folder to (source_folder as string) & DocName & "_ErrorFolder" as alias
			end tell
		end try
	end tell
	tell application "Adobe InDesign CS2"
		tell document 1
			package to error_folder copying fonts no copying linked graphics no copying profiles no updating graphics no ignore preflight errors no creating report yes including hidden layers no
			--			close saving no
		end tell
	end tell
	tell application "Finder"
		--try
		set text_file to (error_folder as string) & "Instruction.txt" as alias
		set the name of text_file to DocName & ".txt"
		--end try
	end tell
end error_report

And throwing error on the line of:

Thanks

Does the file
File Publishing-17:Users:Raj:Desktop:Rajeev Backup:temp:Test123.indd_ErrorFolder:Instruction.txt
exist at all in the specified folder?

btw: I posted a more effective routine to create the folder.
Nested application tell blocks are not recommended, and a double Finder tell block is useless anyway

Hi,

No, the file at location “File Publishing-17:Users:Raj:Desktop:Rajeev Backup:temp:Test123.indd_ErrorFolder:Instruction.txt
exist at all in the specified folder?” is not existing.

I think this file should get created when package will get created. In fact I want to create a package mentioning the missing fonts.

Yes, your routine is fine, I will use that one only.

Thanks

hi,

only problem I am getting is not generated the package report. Does any one have the code or idea to generate package report.

Thanks