Friday, July 28, 2006
Sample Scripts Won't Work
What with family weddings and various other interferences, I've been neglecting this blog for a while. Sorry about that, but the description does warn that entries might be sporadic.
There's been a spate of complaints lately that the sample scripts provided with InDesign CS2 don't work. By which is usually meant: "I double-click the script name in the palette and nothing happens."
The cause of this problem is the userInteractionLevel property. As I wrote back in November (see: Open with no Warnings), a script can control the amount of interaction it does with the user. This is useful for causing dialogs to not appear with warnings that the script doesn't care about.
But:
The solution is simple, once you realize this possibility: simply precede any attempt to show a dialog with:
So, if you're trying to use those built-in sample scripts and they mysteriously refuse to do anything, the quick solution is to save this:
There's been a spate of complaints lately that the sample scripts provided with InDesign CS2 don't work. By which is usually meant: "I double-click the script name in the palette and nothing happens."
The cause of this problem is the userInteractionLevel property. As I wrote back in November (see: Open with no Warnings), a script can control the amount of interaction it does with the user. This is useful for causing dialogs to not appear with warnings that the script doesn't care about.
But:
- The property is application-wide and sticky.
- The property is not stored with the regular InDesign Preferences, so it survives trashing preferences.
- Scripts can accidentally (or negligently) leave it switched off.
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;Then any other script you might run afterwards will not be able to show you dialogs. If they try, it will be as though you clicked Cancel even before the dialog was painted.
The solution is simple, once you realize this possibility: simply precede any attempt to show a dialog with:
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;and the problem goes away. In a perfect world, this should not be necessary because any script which switches off user interaction should switch it back on again before quitting. But scripts have no control over the power company -- to name one reason why a script might not run properly to completion.
So, if you're trying to use those built-in sample scripts and they mysteriously refuse to do anything, the quick solution is to save this:
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;as a script named "RestoreInteraction.jsx" and run it. For a more permanent solution, edit those sample scripts to include this line immediately before the line(s) where the show() method is used to display a dialog.