I’m trying to create a subroutine to create text styles in InDesign. I’ve got a script that creates a document, styles the text, creates pages with content etc.
However, trying to make it more compact and ‘correct’, I thought I’d start using subroutines to do the repetitive stuff, passing the details to the sub using parameters. Here’s a simplified version of my simple subroutine with just a name parameter:
on createParagraphStyle(styleName)
try
set myParagraphStyle to paragraph style styleName
on error
set myParagraphStyle to make paragraph style with properties {name:styleName}
end try
end createParagraphStyle
I’ve tried to call this with ‘on createParagraphStyle(“style name here”)’, but cannot place it anywhere in the script without an error. I’ve tried id within tell statements (using ‘of me’), I’ve tried it at the top of the script, and even after the final ‘end’, but I always get an error and it fails to compile. It’s usually an ‘Invalid key form’ error, but also an ‘expected end or end tell but found…’ error pops up.
The sub compiles fine in a separate script, but I can’t place the sub in another script anywhere (I can put the call in without a problem); how can I make it ‘fit’ in a larger script? I’m sure I’m missing something stupidly obvious, but any help would be appreciated.
I’m using Lion, by the way… if that’s relevant.