tell application “Adobe InDesign CS2”
set theDoc to active document
tell theDoc
delete unused swatches
etc.
However, although this works fine, it converts all the gradients I’ve added to the swatches palette to a solid black! The script leaves the gradient ‘swatches’ in the palette, but just removes the colours and leaves them solid black.
I’ve found that if I make my gradient swatch using colours already in the swatches palette then the ‘delete unused script’ leaves that gradient swatch in the palette. However, If I make the gradient using the colour picker (so the end colours of the gradient aren’t actually defined as swatches) the script converts the whole gradient to black.
tell application "Adobe InDesign CS2"
activate
tell front document
set theUnusedSwatches to unused swatches
repeat with UnusedSwatch from 1 to count of theUnusedSwatches
if name of (item UnusedSwatch of theUnusedSwatches) is not "" then
try
delete (item UnusedSwatch of theUnusedSwatches)
end try
end if
end repeat
end tell
end tell
I’ve been making a script to delete unused swatches and paragraph styles from Indesign CS2 docs. But there’s a problem with the paragraph styles bit. Often when we make up documents we’ll base one paragraph style on a previously defined one (but just change the colour, or the indent, etc.). Now, if the original style isn’t actually being used in the document, and I select ‘Select all unused’ in the styles palette, ID seems to be clever enough to not select the ‘base’ style (because deleting it would remove the formatting from those styles derived from it). However, when I run the script, the base style gets deleted from those docs where it isn’t actually being used.
Here’s the script:
tell application “Finder”
set file_list to selection
repeat with process_item in file_list
set the_alias to alias ((file_list as string) & (process_item))
tell application "Adobe InDesign CS2"
activate
open the_alias
set theDoc to active document
tell theDoc
set myParagraphStyles to every paragraph style of theDoc
set theCount to count of myParagraphStyles
repeat with n from (count myParagraphStyles) to 2 by -1
set myCurrentStyle to item n of myParagraphStyles
my RemoveUnusedStyle(myCurrentStyle)
end repeat
end tell
end tell
end repeat
end tell
on RemoveUnusedStyle(myStyle)
tell application “Adobe InDesign CS2”
set find preferences to nothing
set change preferences to nothing
set theDoc to active document
search theDoc with find attributes {applied paragraph style:myStyle}
tell active document
set myFoundStyles to search theDoc with find attributes {find text:“”}
if (count myFoundStyles) = 0 then
try
delete myStyle
end try
end if
end tell
end tell
end RemoveUnusedStyle
tell application “Adobe InDesign CS2”
try
repeat
tell front document
set theUnusedSwatches to unused swatches
repeat with UnusedSwatch from 1 to count of theUnusedSwatches
if name of (item UnusedSwatch of theUnusedSwatches) is not “” then
try
delete (item UnusedSwatch of theUnusedSwatches)
end try
end if
end repeat
end tell
close front document saving (yes)
end repeat
end try
end tell
Also, for some strange reason, the remove swatches part sometimes has to be run twice before it’ll delete everything.
Hi,
Thanks to Shane over on Adobe’s Indesign scripting forum, I got the solution,. Here’s the script (to be run from within Indesign). I’ve also modified it to run as a batch profess from the Finder.
tell application “Adobe InDesign CS2”
activate
set theDoc to active document
tell theDoc
repeat 3 times – don’t know why, but the script won’t delete all unused swatches on the first run –
set theUnusedSwatches to unused swatches
repeat with UnusedSwatch from 1 to count of theUnusedSwatches
if name of (item UnusedSwatch of theUnusedSwatches) is not “” then
try
delete (item UnusedSwatch of theUnusedSwatches)
end try
end if
set myParagraphStyles to every paragraph style of theDoc
set basedOnStyles to based on of paragraph styles 2 thru -1
set theCount to count of myParagraphStyles
repeat with n from (count myParagraphStyles) to 2 by -1
set myCurrentStyle to item n of myParagraphStyles
if myCurrentStyle is not in basedOnStyles then
my RemoveUnusedStyle(myCurrentStyle)
end if
end repeat
end repeat
end repeat
end tell
end tell
on RemoveUnusedStyle(myStyle)
tell application “Adobe InDesign CS2”
set find preferences to nothing
set change preferences to nothing
set theDoc to active document
search theDoc with find attributes {applied paragraph style:myStyle}
tell active document
set myFoundStyles to search theDoc with find attributes {find text:“”}
if (count myFoundStyles) = 0 then
try
delete myStyle
end try
end if
end tell
end tell
end RemoveUnusedStyle