In one of my plug-ins I need to check whether an external tool is installed.
For this I added in the Plug-in manager a section called "Configuration" with a button.
However I don't want to bother my clients with searching for the executable on the file system.
So I want to execute with a command to check whether it is installed.
LrTasks.execute( command )
Since the code is added to PluginInfoProvider I can't use LrTasks.execute directly, because then I get the error:
We can only wait from within a task.
So I embedded it within a LrTasks.startAsyncTask ( function()
How can I wait for the async task to finish and get the results?
When the async task completes, it could set bound values in a properties table that control UI elements in the custom manager section. E.g. there could be a static_text() that initially shows "Searching for external tool", and when the search finishes, the task sets it to "Found external tool" or "You need to install external tool". You could control the visibility of other elements, etc. as well.
But in general, if you want one async task to wait for a condition (e.g. the completion of another async task), you need to use a spin loop:
while not completed do LrTasks.sleep (0.25) end
While this offends the more delicate architectural sensibilities, practically it works very well and consumes very little CPU, as long as you program it carefully. A number of my plugins are forced to do this for various reasons.
Thank you. You set me in the right direction. Using the property table solved the problem I was facing. Looked in the wrong direction.