I’m guessing the answer here is “You can’t do that.” But just in case I’m wrong, I thought I’d ask.
Background (why I want this - skip if you want)
I’ve got a script that needs to upload and download several large files for users. It’s using LFTP via do shell script. It works really well.
But:
There are several files, and it would be even faster if it handled these in parallel rather than sequentially. LFTP can handle parallel transfer, but in this case it’s not efficient to pass all the files into a single lftp call because the files come from Photoshop doing a modification, then an upload, then a modification, etc. So I don’t have all the files available simultaneously to upload. I could save them all out from PS first, but in many cases the Photoshop run time between saves is significant to the upload time, so that doesn’t necessarily help much.
So I’d like to spin up a new Applescript process for each file transfer to invoke LFTP again. LFTP can handle this, it can manage a queue and perform the operations in parallel.
So I’m just planning on using Bastiaan Boertien’s method here
https://macscripter.net/viewtopic.php?pid=134353#p134353
To run a separate script for each, with the calling script passing in the shell line as an argument.
That way Photoshop can do everything as fast as it can without waiting for each upload to finish before going on to the next step, and the last upload can still be happening when the next is queued and they’ll just upload in parallel.
I can have each script display a new progress dialog window for it’s upload, so the user will be able to see stuff it still going on. But each spun-off Applescript will just be idling while waiting for the “do shell” script to return an Apple Event, so it’s just going to be a “barber poll” style dialog with no updates.
However, sometimes the files are big, and sometimes the users are working remotely on slow connections. It isn’t absolutely essential, but it would be great if there was some way to keep the users notified what was going on. With a standard Applescript progress dialog with 0 updates, they won’t know if an upload hung or is going to take 20 minutes or what.
What I want
LFTP provides great feedback - in Terminal.
So my question is, is there any way to feed the shell output back to an Applescript- live? Not setting a variable to the result of the “do shell script” command and waiting for it to return, but feeding what’s being shown in the shell back to Applescript while the user waits, so it could update a progress dialog?
The only ways I could think to do this are:
-
Forget “do shell script” and just actually applescript Terminal to show a shell and run the command… and have the shell script exit, and close the window on a clean shell exit. But people tend to freak out when a terminal window pops up, it’s not very UI friendly.
-
Use Platypus or CocoaDialog
https://sveinbjorn.org/platypus
to make the shell script for lftp into an application, that accepts arguments in the $n format for the variables. Although it’s unclear to me, if Applescript is calling this as an application, if there’s any way to actually pass those variables. But It looks like Platypus or Cocoa Dialog can display what the terminal would be displaying in a UI window.
I’m not thrilled with either of those options, thought I’d ask if there’s a better way.
Thanks,
t.spoon