I’m a noobie, please forgive my noobieness. I want to delete all unused colors in the swatch palette. I attempted this script:
tell application “Adobe Illustrator”
tell front document
tell swatch
select menu item “select all unused”
select menu item “delete swatch”
end tell
end tell
end tell
And that gets me an error message: Can’t get <> “select all unused” of <>
Nice try! The main problem is that Illustrator does not provide a way to speak to swatches quite that directly. You could use one of the default actions in CS2 called “Delete Unused Palette Items” like this:
tell application "Adobe Illustrator"
-- run an Illus. Action:
do script "Delete Unused Palette Items" from "Default Actions" without dialogs
end tell
The “do script” command runs Illus. actions by listing the desired action by name, followed by the name of the set it’s located in as shown above.
This will also delete any unused brushes, styles and symbols. If that’s too radical for your purposes you would need to create an action that just deleted unused swatches. The only menu command that allows Illustrator to identify the unused swatches is in the Swatches palette, and it unfortunately can’t be reached via script (not directly anyway…)
hello noob! and welcome. There is a action in illustrator defaults to remove all unused palette items you could have your script call that. It does need to be run twice as in the GUI and you’ll still be left with “Smoke” in swatches. I think this is used in a default somewhere but haven’t found it yet.
tell application "Adobe Illustrator"
activate
set docRef to the current document
do script "Delete Unused Palette Items" from "Default Actions"
delay 1
do script "Delete Unused Palette Items" from "Default Actions"
end tell
Thank you for your help! I am understanding the logic better now. However, I got this error message: “Adobe Illustrator got an error: The ‘do script’ command cannot be executed from the Scripts menu” when I ran both examples:
tell application “Adobe Illustrator”
– run an Illus. Action:
do script “Delete Unused Palette Items” from “Default Actions” without dialogs
end tell
tell application “Adobe Illustrator”
activate
set docRef to the current document
do script “Delete Unused Palette Items” from “Default Actions”
delay 1
do script “Delete Unused Palette Items” from “Default Actions”
end tell
ditto here, I thought the do script to call an action would be an easy option for you here. Runs fine from Script Editor & Menubar Scripts just not the internal execute script. Not sure why that would be.
Not tried it in a script but if it helps i have this action assigned to a function key you do have to hit the key twice
sometimes but it is still quick and it works.
I believe Mark67’s only problem is you forgot to tell docRef
tell application "Adobe Illustrator"
activate
set docRef to the current document
tell docRef
do script "Delete Unused Palette Items" from "Default Actions"
delay 1
do script "Delete Unused Palette Items" from "Default Actions"
end tell
end tell
doh. thanks pretech and would you believe I C&P from a script where it was sat inside the tell doc block. Of cause the items are of document and not application. more haste less speed ooops.