Copy link to clipboard
Copied
Hi,
We can invoke the menus using MenuActions. How can i disable/enable InDesign's built-in menus using indesign javascript?
(…) Can we disable (stop) the process of only export PDF from Export menu?
I think so. The ImportExportEvent object has a format property that should be useful to filter file format.
In the callback function (disableProcess), you could add a condition of the form:
if( ev.properties.format == … ) etc
@+
Marc
Copy link to clipboard
Copied
(…) Can we disable (stop) the process of only export PDF from Export menu?
I think so. The ImportExportEvent object has a format property that should be useful to filter file format.
In the callback function (disableProcess), you could add a condition of the form:
if( ev.properties.format == … ) etc
@+
Marc
Copy link to clipboard
Copied
HI,
The below code stop the process of export pdf using event format beforeExport. But when i click the export menu (Adobe PDF Print) the below dialog appeared and then only process gets stop. Can I skip this dialog??
Similary for Adode PDF (Interactive).
Can i use jsxbin file instead of jsx in startup script folder?? it will work without any issue??
Code:
#targetengine "exportPDF"
main();
function main() {
//var myApplicationEventListener = app.eventListeners.add("afterExport", disableExportOption, false);
var myApplicationEventListener = app.eventListeners.add("beforeExport", disableExportOption, false);
}
function disableExportOption(evt) {
if(evt.format == "Adobe PDF (Interactive)" || evt.format == "Adobe PDF (Print)")
{
alert("Don't Export PDF as Manual. Use Script to Export PDF!!");
evt.stopPropagation();
evt.preventDefault();
return;
}
}
Copy link to clipboard
Copied
Hi Sudha K,
As commented in the code at #20, the best solution would have been to listen to the submenu actions [High Quality Print], [PDF/X-1a:2001] and so on, using the beforeInvoke event. I tried this approach first, but it didn't work for me. So we seem to have no choice but to detect the beforeExport event, downstream. Alas, it only occurs once the user has validated the Export Adobe PDF dialog.
Maybe there is a way to hook that dialog, I don't know.
> Can i use jsxbin file instead of jsx in startup script folder?? it will work without any issue??
1. Compile the script without its #targetengine directive.
2. Open the jsxbin in an editor, remove line breaks and copy the entire string.
3. Create a jsx with:
#targetengine "<yourEngine>"
eval("<yourJsxBinString>");
@+
Marc
Copy link to clipboard
Copied
Hi,
Thank you.... Its working...
Copy link to clipboard
Copied
Hi Sudha,
see into the properties of the event that goes into your handler function.
There is property event.fullName with the value of the file that will export.
You could check the suffix from that and react accordingly.
Regards;
Uwe
Copy link to clipboard
Copied
See also DOM documentation for the importExport event. From Jongware:
Adobe InDesign CS6 (8.0) Object Model JS: ImportExportEvent
Regards,
Uwe
Copy link to clipboard
Copied
Hi,
thank you for the reply...
I will check and get back...
Copy link to clipboard
Copied
You're absolutely right about the potential threat. I seem to remember we touched that topic before.
A script should NEVER use instructions of the form …eventListeners.everyItem().remove()—unless you are in the process of fixing a critical bug that totally breaks ID!
I plead guilty for removing event listeners in that way as part of testing my code without restarts, but I think it is a bug that the event listeners are shared. Target engines are supposed to be isolated, at the C++ side there is plenty code dedicated to engine awareness. EngineContext or RequestContext pointers passed all over the place. On the other hand, this opens interesting ways of inter-engine communication.
#targetengine Foo
app.eventListeners.add(Application.AFTER_ACTIVATE,dummy);
function dummy(){"Foo!"}
dummy.secret = "oops!";
$.writeln($.engineName);
$.writeln(app.eventListeners.length);
#targetengine main
var el = app.eventListeners.lastItem();
$.writeln($.engineName);
$.writeln(el.handler.toSource());
$.writeln(el.handler.secret);
Copy link to clipboard
Copied
Hi Dirk,
I plead guilty for removing event listeners in that way as part of testing my code without restarts, but I think it is a bug that the event listeners are shared. Target engines are supposed to be isolated, at the C++ side there is plenty code dedicated to engine awareness. EngineContext or RequestContext pointers passed all over the place. On the other hand, this opens interesting ways of inter-engine communication.#targetengine Foo app.eventListeners.add(Application.AFTER_ACTIVATE,dummy); function dummy(){"Foo!"} dummy.secret = "oops!"; $.writeln($.engineName); $.writeln(app.eventListeners.length);
#targetengine main var el = app.eventListeners.lastItem(); $.writeln($.engineName); $.writeln(el.handler.toSource()); $.writeln(el.handler.secret);
Nice trick. You need to access the right eventListener though—and lastItem() is usually not a safe specifier 😉
Also, itemByName(myUniqueIdentifier) is not supported in CS4 (for eventListeners.)
So in absolute terms we either need a unique DOM id (which is not necessarily known from the co-script at hard-coding time), or some lookup mechanism throughout existing listeners and their associated handlers.
Question: What's your opinion about using $.setenv() and $.getenv() to share data across the session? I use that approach in IdExtenso, in particular in the Settings module. To your knowledge, is there any drawback with it?
Best,
Marc
Copy link to clipboard
Copied
Marc, of course you could add the event listener to some obscure object where nobody looks. Anyway it is a hack and I would not be surprised if the next garbage collection blows up straight into your face, or similar side effects.
Regarding $.getenv, that is for processes sharing string values with child processes. So if you launch InDesign from a shell script and want to pass a file name, that could be an option. Pick up the Unix user name. Also the opposite way, when you fork sub-processes from InDesign. I recently learned that Photoshop has app.system, maybe even File.execute would pass the environment. Better don't use it to store gigabytes, and the environment is shorter lived than app.insertLabel and friends. Also avoid variables that have special meanings, e.g. DYLD_LIBRARY_PATH.
Copy link to clipboard
Copied
Hi, Can you please share the script property to disable below options in InDesign.
Copy link to clipboard
Copied
Hi,
If we disable the visibility in an InDesign, the corresponding menu item is hidden inside the InDesign application. Do you want to this ? or just disable the functionality of the menu item?
Copy link to clipboard
Copied
Hi, I want to hide the "Fill with Placeholder Text" in right click option.
Copy link to clipboard
Copied
Here is another resource you may find interesting: Prevent executing menu items | IndiSnip [InDesign® Snippets]
So far as tutorials, if you download the Javascript SDK InDesign SDKs and tools | Adobe Developer Connection there are some eventlistener tutorials that may assist you.
Copy link to clipboard
Copied
Thank you...
I will check the given links...