This question has been inspired by the question 'Call script from command line'.
How can one write a script which acts on 'trigger events' in an application other than DigitalMicrograph?
i.e. some script functionality should be triggered by an external application.
The scripting language does not offer many 'external' interfaces in its current state. It is possible to call out to an external process with the command
LaunchExternalProcess
and wait for the process to complete, but there is no straight-forward way for an external process to call in, i.e. to start a script-action within DigitalMicrograph.However, it is possible to work around that issue by using the system's file-system as a message queue. To do this, have a script running in the background which regularly checks if a certain file exists, and have the external application create such a file when it wants to trigger a scripting-action in DigitalMicrograph. The file content - if it is a simple text file - can also be used to transport information between the two applications.
Here is an example script which will wait until the file
Trigger.txt
appears in the root folder. The check is performed every 10seconds.Note that the periodic task waits idle in the background without interfering with the CPU, but the actual check is then performed on the main thread.