Copy link to clipboard
Copied
Hi,
I am developing a small ExtendScript extension for FrameMaker and I need to periodically check a service. As I see, there is no setTimeout/setInterval implementation available, so from ExtendScript that is not possible to implement a non-blocking wait cycle. 1) Am i right? Or is there any workaround that I haven't found yet?
2) I also saw that you can subscribe for idle task in InDesign. I wonder if there is any similar function to subscribe to the main loop in FrameMaker?
3) If none of above exists, my final idea for the problem is to start a script in Framemaker from outside (command line). Is there any solution for this?
Thanks in advance!
Best regards,
Balazs
Copy link to clipboard
Copied
There is no async capability at all in FrameMaker or ExtendScript.
You can do a wait with $.sleep() but this is blocking.
There is an event loop in FrameMaker though, which can be used to trigger code based on the user (or another plugin) triggering certain events. Look into the Notification() and Notify() functions.
There is not a lot of info in the scripting guide on this, but if you look at the same functions in the FDK documentation, there is a decent overview of how the notification system works.
Copy link to clipboard
Copied
1) Thanks, for confirmation
2) Yes, but can i use that loop to periodically check something? As you said, i can subscribe for specific events, but as i see there is no option to receive a notification in every 5-15-30 sec?
Copy link to clipboard
Copied
Hello,
I have 2 blog posts that might help you solve this:
In this example below, we will schedule a task to run ever 3 seconds and then stop after 9 seconds.
The task is set to create a text document on your Desktop that says "Hello world!". If you delete the text file, it will automatically be created 3 seconds later in the background.
Cheers,
Breton
var seconds_run = 3; // run every 3 seconds
var seconds_stop = 9; // stop after 9 seconds
// Function that contains the command to be executed after the delay
function delayedCommand() {
var command = 'echo "Hello world!"';
var outputFile = "~/Desktop/output.txt";
system.callSystem('nohup ' + command + ' > ' + outputFile + ' 2>&1 &');
}
// Stringify the function to be passed to app.scheduleTask
var recurringTaskString = delayedCommand.toSource() + "()"; // Adding code between this line and your delayedCommand function might break ExtendScript.
// Schedule the recurring task (third argument true for repetition)
var taskId = app.scheduleTask(recurringTaskString, seconds_run*1000, true); // Repeat every 5 seconds
// Cancel the recurring task
var cancel_task = "app.cancelTask(" + taskId.toString() + ")";
app.scheduleTask(cancel_task, seconds_stop*1000, false); // Repeat every 5 seconds
Copy link to clipboard
Copied
Unfortunately app.scheduleTask() is not available in FMs ES engine...
The same holds for system.CallSystem().
So IMHO the only (possible) solution may go along the following idea:
Schedule a task outside of FM by means of the Windows Task Scheduler. The task, however can not interfere with FM besides opening it (probably with a specific document). This document may run a script by means of a hyptertext command message openfile script-path (see FMjsxLib.pdf , "Invoking script by Hypertext command"). But alas, even this requires a user intervention, as it aks whether you really want to execute the script...
Conclusion: ES implementation in FM is meager.