Building a script to generate cover spreads for publications based on a folder of pdfs. Trying to get my head around sub-routines to simply my script layouts. The following script errors when trying to run the Indesign handler from inside the “Tell Application Finder” / “End Tell”.
tell application "Finder"
set CoverFldr to choose folder "Where are the cover pdfs?"
set CoverPDFs to every file of folder CoverFldr
set PDFcount to the count of CoverPDFs
if PDFcount is not equal to 4 then
display dialog "4 PDF files required to cover assembly. Please check"
else
makecover(CoverFldr)
end if
end tell
-- display dialog PDFcount as string
on makecover(CoverFldr)
tell application "Adobe InDesign CS3"
activate
-- Indesign build component
end tell
end makecover
I can work around this by removing the “makecover” handler from inside the “Tell” statement. Like this:
set CoverFldr to choose folder "Where are the cover pdfs?"
tell application "Finder"
set CoverPDFs to every file of folder CoverFldr
end tell
set PDFcount to the count of CoverPDFs
if PDFcount is not equal to 4 then
tell application "Finder"
display dialog "4 PDF files required to cover assembly. Please check"
end tell
else
makecover(CoverFldr)
end if
-- display dialog PDFcount as string
on makecover(CoverFldr)
tell application "Adobe InDesign CS3"
activate
-- Indesign build component
end tell
end makecover
But the idea of using multiple “Tell Finder” statements seems counter intuitive. What is the correct syntax to make the script at the top function correctly.
You could get rid of the Finder tell block by turning it into a line, there is no real need to have the other lines of code inside the Finder Tell Block.
set CoverFldr to choose folder "Where are the cover pdfs?"
tell application "Finder" to set CoverPDFs to every file of folder CoverFldr whose file extension is "pdf" as alias list
set PDFcount to the count of CoverPDFs
if PDFcount is not equal to 4 then
display dialog "4 PDF files required to cover assembly. Please check"
else
makecover(CoverFldr)
end if
-- display dialog PDFcount as string
on makecover(CoverFldr)
tell application "Adobe InDesign CS3"
activate
-- Indesign build component
end tell
end makecover
Thanks (as always) for the tip.
Trying to work sub-routines into my scripts now that they are getting a bit bigger.
Matt
Ps. What editor do you do the bulk of your scripting in? Script Editor? Script Debugger? Keen to know the benefits (if any) of moving away from the script editor.
Thanks. So from my understanding of AS, it is a initially addressing the system and the “Tell Finder” is just directing it to a particular component of the system (If you like) so there is no requirement for “End Tell” as it’s all system.
Script Debugger, as the name implies it has extraordinary debugger skills like watching variable values and single step execution also with breakpoints.
The disadvantage is the price, but if you do serious script developing it’s worth its price.
I just used the one line tell style for the command which can be used with any application. If the command is more than one line then you need the end tell, just like you would with an if then statement.