I would like an action to await the creation of a specific file in Dropbox (and then read it). A timeout value for this would be a bonus.
Any idea how to do this?
I thought of a read with repeat every second or so. But there isn’t a setTimeout() equivalent so far as I know.
(The fuller scenario is that the draft would create a file in Dropbox that my Mac would use Hazel to detect and act on. The Mac workflow would create a “results” file that I’d like the Drafts action to retrieve. There might be better ways of doing this, of course.)
The way you’re doing it is one approach, but I guess the ideal approach for processing on the Mac would be to have a web service where you passed in the file and it waited for the file to be processed, and then passed the results back. The approach you have currently is push and poll rather than push and receive. Therein lies the underlying issue.
Another alternative would be to do whatever Hazel is doing remotely, locally. Perhaps there is scope to process the file using Drafts, or Shortcuts/Pythonista/Scriptable/etc., and then capture the results of that processing?
On that basis you would have to look at repeating the read a number of times with a delay between each; after which you would abort if no change had been detected.
I can’t think of anything else reasonable to do that would be precise to incur a delay except some date/time calculations.
let dtStart = new Date().getTime();
for (let intCounter = 0; intCounter < 999999999; intCounter++)
if ((new Date().getTime() - dtStart) > intms)
//Wait 3 seconds
alert("Do something else");
Another thought. You could have Drafts trigger something with Shortcuts using the Run Shortcut action step, and return once it’s operations are complete, potentially with additional data.
Whilst you could use Shortcuts to do the same pause and check game as above, you could equally use it to trigger an SSH interaction with your Mac. You could use this SSH session to have the Mac check for the results file, or to have it trigger the operations you require (outside of Hazel though as you are manually triggering) and then pass back the result directly.