I may be missing something here, but it seems to me that in applescript it is not possible to pass a handler to the ‘do script’ command, which is the only way to be able to control how InDesign handles undoing your script, it will only accept a string. Is this correct?
Working on the assumption that it is, I’m trying out using the code below to encapsulate scripts so that they call themselves. I’ve done it because I’m getting tired of making whole scripts into strings and escaping all the quotes within, only to have to un-escape them all it if I want to edit the script and compile it for testing.
[b]
property runNow : false – change this to true to debug
property undoName : “Test undo name”
if runNow then
– do stuff
tell application “Adobe InDesign CS5”
– do stuff
end tell
-- important return statement.
-- stack overflow without
return
end if
---- workings
set scriptAlias to (path to me)
set scriptPath to (scriptAlias as string)
set theScript to load script scriptAlias
if not theScript’s runNow then
theScript’s toggleRun()
end if
if theScript’s runNow then
store script theScript in (path to me) with replacing
tell application “Adobe InDesign CS5”
do script scriptPath undo mode entire script undo name undoName
end tell
end if
on toggleRun()
if runNow then
set my runNow to false
else
set my runNow to true
end if
end toggleRun
---- workings
[/b]
It’s just occurred to me that I could also use a script bundle with the main script calling another script from within it’s bundle, which is possibly a more elegant solution.