Need help using Applescript to load swatches in InDesign

I’m muddling my way through building an Applescript that is designed to load swatches in InDesign (currently scripting for CS2) and then change the swatches originally in the document to those newly loaded swatches based on matching numbers in the swatch names (e.g., replace Old-1 with New-1, Old-2 with New-2, etc.).

Currently, I’m struggling with the right syntax for loading swatches. With the target InDesign file open, I’m trying to tell it to load a specific set of swatches (e.g., all those that start with “New”) from another InDesign file that contains all of the possible swatches. I’ve tried too many variations to list here, but if someone could show me the correct syntax I’d be grateful.

In case it helps clarify the issue, I’m using Script Editor 2.2 and OS X 10.5 (Leopard). Here’s part of my script-in-progress and the error it generates:


tell application "Adobe InDesign CS2"
		load swatches from "/Users/kevins/Desktop/TestMonkey.indd"
	end tell

The Applescript error (from dialog box when trying to run the script, which compiles OK): Adobe InDesign CS2 got an error: Cannot load swatches from selected document. Either this is not InDesign document or the document is damaged.

I’m also running into much the same problem when I try to tell InDesign to open a file, which may be part of the problem with loading swatches from another file. The document is indeed an InDesign file, so my syntax must be flawed.

Again, any tips would be very much appreciated.

Thanks,
Kevin

Model: G5
AppleScript: 2.0
Browser: Firefox 2.0.0.11
Operating System: Mac OS X (10.5)

Hi Kevin,

looking into the dictionary of ID CS2 the load swatch command expects an alias or a string (HFS path)


tell application "Adobe InDesign CS2"
	load swatches from alias ((path to desktop as Unicode text) & "TestMonkey.indd")
end tell

or


tell application "Adobe InDesign CS2"
	load swatches from ((path to desktop as Unicode text) & "TestMonkey.indd")
end tell

Thanks Stefan. That worked great for the test file on my desktop. But if I try to move the file to another location – either on my Mac or on a server – the script errors. For example:


oad swatches from ("/Kevin's_HD/Projects/RenameIDparaStyles/nhm0800colors1.indd" as Unicode text)

gives the same “Cannot load swatches from selected document. Either this is not InDesign document or the document is damaged.” error.

Any attempt I’ve made so far at specifying the path, for example:


set MyPath to "/MyHD/MyFolder/MySubFolder/MyFile" as Unicode text

either gives an error that it can’t find the file or it just won’t compile. I’ve tried many different variations, putting the path in quote marks, using “:” instead of “/”, inserting “as Unicode text” or “as alias” in different spots, and have also tried trying to specify the path and then adding the file name separately as in your example.

Obviously, I have a lot to learn about specifying paths to files. Again, any help would be appreciated. If I can get the swatches loaded from a file, I can start working on the heart of the task … replacing existing swatches with the newly loaded ones!

Thanks again,
Kevin

A HFS path is colon separated and starts always with the name of the disk

this is a POSIX path (slash separated) which doesn’t work
btw: the coercion as Unicode text is useless, a literal string is Unicode text

this should work:


load swatches from ("Kevin's_HD:Projects:RenameIDparaStyles:nhm0800colors1.indd")

Now my script is filling up with “thanks to Stefan” comments. The use of a colon-separated path was the key. Thanks again, Stefan, for patiently explaining this to me. Now I can move on with the task of replacing swatches (so chances are I’ll be posting again soon!).

Kevin