InDesign CS2 Script Help

Hi Fellow Users

I needs some help to formulate a script that can do the following in Adobe CS2 InDesign. I am new to scripting, and would appreciate some help from anyone that can help?

Briefly - We supply low resolution picture files (links) to our clients to use in the creation process of their documents. On return of the files to our site we have to update the link status to the high resolution links in order to prepare the files for print output. Updating the links is done via the link manager window, and is handled one at a time. I have found a script that allows me to point to the folder on a server that contains the high resolution links, and update all links at once. A great time saver, and removes the risk of error. The problem that I am having is that there is the odd time when a link is updated, but still has the low resolution in the file? What I was thinking is that an additional section of code could be added to the script to produce a list of links post update that are below a certain threshold, as most of the links are always above 5MB in size. Once this list is produced the operator processing the InDesign file can check the suspect links and make sure that they are updating to the correct ones.

If anyone knows how to do this and can help me I would be most grateful.

I have included the script that I use to update all the links which needs to have the extra lines added to it.

Many thanks

Malcolml

global foundPaths, foundPathNames
set foundPathNames to {}
set foundPaths to {}
set missedLinks to “” – name of links not found
tell application “Adobe InDesign CS2”
activate
– choose pic folder
set folderpath to (choose folder with prompt “Choose folder containing pictures:”) as Unicode text
tell document 1
set missingLinks to every link whose status is link missing
if missingLinks is not {} then
set missingLinkNames to name of every link whose status is link missing
set linkcount to count of items of missingLinkNames
– search for file recursively
my checkforfile(folderpath, missingLinkNames, linkcount)
set foundCount to count of items of foundPathNames
– see if file was found, and relink if so
repeat with i from 1 to linkcount
repeat with j from 1 to foundCount
if contents of item j of foundPathNames = contents of item i of missingLinkNames then
relink item i of missingLinks to alias (item j of foundPaths)
exit repeat
else if j = foundCount then
set missedLinks to missedLinks & (item i of missingLinkNames) & ", "
end if
end repeat
end repeat
try – in case there aren’t any
update (every link whose status is link out of date)
end try
if missedLinks = “” then
display dialog “All links updated.”
else
display dialog "The following links weren’t found: " & return & (text 1 thru -3 of missedLinks)
end if
else
display dialog “No links missing.”
end if
end tell
end tell

on checkforfile(folderpath, fileNames, n)
set theList to list folder file folderpath without invisibles
repeat with anItem in theList
set thePath to alias (folderpath & anItem) as Unicode text
if thePath ends with “:” then
set searchResult to my checkforfile(thePath, fileNames, n)
if searchResult is false then
return false
end if
else if contents of anItem is in fileNames then
set end of foundPathNames to contents of anItem
set end of foundPaths to thePath
if (count of items of foundPaths) = n then
return false
end if
end if
end repeat
return true
end checkforfile

I won’t write the whole script for you - but something like this should suffice I think: Just add the appropriate parts of this into your repeat loop somewhere and you should be good to go. Or you could run it as a standalone.

tell application "Adobe InDesign CS2"
	activate
	tell document 1
		set mylinks to links
		repeat with i in mylinks
			set theName to name of i
			set theSize to (((size of i) / 1024) / 1024) as number
			if theSize < 5 then
				do shell script "printf  \"" & theName & "	" & theSize & return & "\">>~/Desktop/too_small.txt"
			end if
		end repeat
	end tell
end tell

Thanks for the help, it works fine. I wanted to add something to make it more apparent to our operators that something has happened, as sometimes they are busy to the point that if they don’t have a visual warning about what has happened and that some items have been located and put into the .txt file on the desktop, that they may just move on under the assumption that all is OK and leave the file as it is without first checking out the suspect images.

What I was hoping is that something like “No LowRES were found” might be added to come up if all images are above the threshold of 5MB, and if some are found below, that something like “LowRes images found, check desktop report.txt” comes up, meaning that the operator would have to acknowlege the warning by clicking the OK button on the warning window.

Your help is most appreciated.

Thanks

Malcolml

try this:

property myerror : 0
tell application "Adobe InDesign CS2"
	activate
	tell document 1
		set mylinks to links
		repeat with i in mylinks
			set theName to name of i
			set theSize to (((size of i) / 1024) / 1024) as number
			if theSize < 1 then
				do shell script "printf  \"" & theName & "	" & theSize & return & "\">>~/Desktop/too_small.txt"
				set myerror to 1
			end if
		end repeat
	end tell
end tell

tell application "Finder"
	activate
	if myerror is 0 then
		display dialog "No LowRes images found" buttons "Great!" default button 1 giving up after 20
	else
		display dialog "LowRes images found, check desktop report.txt" buttons "OK" default button 1 giving up after 20
	end if
end tell

Hi Chris

Thanks for the revised script, this will work nicely and solve my problem.

I wish I could get my head around the syntax.

BTW where can one get the basics to learn what you just did for me?

Anyway thanks for taking timeout to help me with this I really appreciate it.

Thanks

Malcolml:)

Malcolm:
You are the greatest. Thanks so much for that script. I modified it to allow the user to change the first part of the name of the link to another prefix. For example, if your file name is “hi-res_womanInBlue.jpg” you could change it to “lo-res_womanInBlue.jpg”. It works for all the links in the file with the prefix you specify. We use this to change the links on our newsletter stories, where all the sublinks for one particular story start with “closeup” for example, and we want to change them to “fund” etc.

Cheers,
Mooncalf

global foundPaths, foundPathNames
set foundPathNames to {}
set foundPaths to {}
set newLink to {}
set missedLinks to "" -- name of links not found
set oldAbbrev to "" -- old name of abbreviation of story name
set newAbbrev to "" -- new name of abbreviation of story name
set monthYear to "" -- monthYear combo


--note icon 1 = icon of the application you're in. cool!
--get the old abbreviation here 
display dialog "Please enter the abbreviation of the OLD link name (example: template, OnIncome, OnStocks):" default answer "OnFunds" buttons {" Cancel ", "OK"} default button "OK" with icon 1
set myResult to the result

if the button returned of myResult is "OK" then
	set oldAbbrev to the text returned of myResult
end if

-- setting to length so can compare to link...
set oldAbbrevLength to length of oldAbbrev
set oldAbbrevLengthPlusOne to (oldAbbrevLength + 1)
--display dialog "the length of the oldAbbrev is " & oldAbbrevLength
--set test to "closeupTEST"
--set mytest to characters 1 thru oldAbbrevLength of test
--display dialog "the string is " & mytest


--get the new abbrev here
display dialog "Please enter the abbreviation of the NEW story link name you want:" default answer "OnStocks" buttons {" Cancel ", "OK"} default button "OK" with icon 1
set myResult to the result

if the button returned of myResult is "OK" then
	set newAbbrev to the text returned of myResult
end if

--enter the month + dash + year
--display dialog "Please enter the month-year combo you want (example: 02-07):" default answer "01-07" buttons {" Cancel ", "OK"} default button "OK" with icon 1
--set myResult to the result

--if the button returned of myResult is "OK" then
--	set monthYear to the text returned of myResult
--end if



tell application "Adobe InDesign CS2"
	activate
	-- choose pic folder
	--set folderpath to (choose folder with prompt "Choose folder containing pictures:") as Unicode text
	--display dialog "folder path = " & folderpath
	tell document 1
		--set allLinks to every link whose status is link missing
		--okay no need for this second array, but it was already there...
		--yes, did not bother to rename it
		set allLinks to every link
		if allLinks is not {} then
			
			--get array of link names
			set linkNames to name of every link
			
			--get array of link paths
			set linkPaths to file path of every link
			
			
			--set linkNames to name of every link whose status is link missing
			set linkcount to count of items of linkNames
			--note that link names and link paths are the same length, hopefully!
			--set pathcount to count of items of linkPaths
			
			--echo back length of array
			--display dialog "the link count is" & pathcount
			
			
			-- search for file recursively
			--my checkforfile(folderpath, linkNames, linkcount)
			--set foundCount to count of items of foundPathNames
			-- see if file was found, and relink if so
			repeat with i from 1 to linkcount
				
				set myLinkName to contents of item i of linkNames
				set myLinkPath to contents of item i of linkPaths
				--display dialog myLinkPath
				
				--set length of my name for further string parsing below
				set myLinkNameLength to length of myLinkName
				set myLinkNameLengthPlusOne to myLinkNameLength + 1
				
				set myLinkPathLength to length of myLinkPath
				
				--declare variables to be filled below
				set myLinkNamePart1 to ""
				set myLinkNamePart2 to ""
				set myLinkNewName to ""
				set myLinkBasePath to ""
				
				--only perform action if link names is longer than the original abbrev. if it's shorter, then it's totally unrelated...
				if myLinkNameLength ≥ oldAbbrevLength then
					set myLinkNamePart1 to characters 1 thru oldAbbrevLength of myLinkName as string
					set myLinkNamePart2 to characters oldAbbrevLengthPlusOne thru myLinkNameLength of myLinkName as string
					set myLinkBasePath to characters 1 thru -myLinkNameLengthPlusOne of myLinkPath as Unicode text
					
					--display dialog "my link name part 1 = " & myLinkNamePart1 & " and my oldAbbrev = " & oldAbbrev
					--display dialog "my link base path =" & myLinkBasePath
					
				end if
				
				
				--if the link contains the old abbreviation, then switch out to the new abbreviation
				if oldAbbrev = myLinkNamePart1 then
					--display dialog "the last half of the name is " & myLinkNamePart2
					set myLinkNewName to newAbbrev & myLinkNamePart2
					set myNewLinkArray to {myLinkNewName}
					--display dialog "my new link name is " & myLinkNewName
					set newLink to myLinkBasePath & myLinkNewName as Unicode text
					
					--use that other guys function. check that link exists
					--I'm using his function differently. Only looking for one file...
					my checkforfile(myLinkBasePath, myNewLinkArray, linkcount)
					set foundCount to count of items of foundPathNames
					--display dialog "foundCount for " & "myLinkNewName = " & foundCount
					
					
					if foundPathNames is not {} then
						relink item i of allLinks to alias (newLink)
					else
						set missedLinks to missedLinks & (item i of linkNames) & ", "
					end if
				end if
				
				
			end repeat
			try -- in case there aren't any
				update (every link whose status is link out of date)
			end try
			if missedLinks = "" then
				display dialog "All links updated."
			else
				display dialog "The following links weren't found: " & return & (text 1 thru -3 of missedLinks)
			end if
		else
			display dialog "No links missing."
		end if
	end tell
end tell

on checkforfile(folderpath, fileNames, n)
	set theList to list folder file folderpath without invisibles
	repeat with anItem in theList
		set thePath to alias (folderpath & anItem) as Unicode text
		--display dialog "the path = " & thePath
		if thePath ends with ":" then
			set searchResult to my checkforfile(thePath, fileNames, n)
			if searchResult is false then
				return false
			end if
		else if contents of anItem is in fileNames then
			--display dialog "found " & anItem & " in this folder"
			set end of foundPathNames to contents of anItem
			set end of foundPaths to thePath
			--if (count of items of foundPaths) = n then
			--	return false
			--end if
		end if
	end repeat
	return true
end checkforfile

Model: G5
AppleScript: 1.10.7
Browser: Safari
Operating System: Mac OS X (10.4)