Copy link to clipboard
Copied
Hello,
I have done an applescript which works fine. However some of the actions related to the system (do shell script...) are taking a while to complete.
And as long as they are running, user can't keep on working.
I was wondering if I could separate what is related to indesign from what is not related to Indesign in order to give control back on indesign to the user while soem actions are still processing on the background ?
I have found a way to dissociate script thanks to load script command but it doesn't prevent Indesign to freeze until the external script completion.
Do you think it's possible ?
Loic
What I mean is AppleScript's 'do shell' command will wait for a response from the system… Im only Leopard so I can't say for sure if anything has changed… So this will hold your main script until a result/error is received before continuing with the rest of your commands… If you called system from Bridge or Photoshop then they would just send the shell string… And wait for nothing… Not locking up your main script…
Copy link to clipboard
Copied
You can have asynchronous shell by swapping your app do script applescript do shell for a bridgetalk message to either photoshop or bridge… Both have app.system();
Edit:
Yep after posting that… It registered that you are NOT using ESTK javascript and calling AppleScript to do the shell… Just have either of the two apps do javascript with app.system();
if you have access to them…
Copy link to clipboard
Copied
Hi Mark,
Thanks a lot for your input. So using do script will lead to main script exit while the code sent in do script will complete within Photoshop ?
Won't the main script wait for do script completion ?
Loic
Copy link to clipboard
Copied
What I mean is AppleScript's 'do shell' command will wait for a response from the system… Im only Leopard so I can't say for sure if anything has changed… So this will hold your main script until a result/error is received before continuing with the rest of your commands… If you called system from Bridge or Photoshop then they would just send the shell string… And wait for nothing… Not locking up your main script…
Copy link to clipboard
Copied
Hi Mark,
Thanks a lot, that makes sense. I will try that.
Loic
Copy link to clipboard
Copied
I suspect this is not going to help you.
If you want to run a shell command in the background, you can just append "&" to the command it will run asynchronously and control will return immediately.
But I presume you want InDesign to un-freeze while that is happening.
If so, you'll need to convert your script to be event-driven. Install a handler and make sure that your shell script calls the handler when it is done. Either via Bridgetalk or via Appleevents.
Maybe a more concrete example would be good.
Copy link to clipboard
Copied
Hi John,
My code is rather heavy but I have tried to summarize the mainline :
on main()
(*
PART A
Several Indesign operations
tell application "Adobe InDesign CS5"
...
end tell
*)
(*
PART B
--Several commands including :
-> write files (open for access...)
-> Zip files (do shell script)
-> Http post with curl (do shell script)
-> Rename files (do shell script)
-> Remove files (do shell script)
*)
end main
So it's Part B I would like to be operated outside of Indesign and you got it, unfreeze Indesign after Part A. I guess the "&" trick you propose may still accelerate things a bit but in fact each command is related to each other so it's probably better to wait for completion. I will give bridgetalk too but as the logic concerns both Indesign and Xpress, Bridgetalk is half a solution in the sense where Xpress won't offer that command. Appleevents...Well never play with them but I guess it's all I have.
FWIW, I tried with simple files "load script" and "run script" commands. Load keeps indesign frozen and run script looks like it unfreezes Indesign but it awfully manageable as long as the ran script has not finished.
Thanks for all,
Loic
Copy link to clipboard
Copied
Loic:
In your example, everything in your example after the InDesign work seems to run independently as a sequence of shell scripts.
If that's the case, simply combine them into one long shell script (string them together with semicolons. Or if that feels wrong, write them to a file and execute the file), and then wrap the whole thing in parens and add an amperand: "(cmd1; cmd2; cmd3; cmd4; cmd5) &"
Then they will all run in sequence and the InDesign applescript will just return.
This doesn't sound like what you asked for in the first post though -- did you oversimplify?
When I said AppleEvents I really just meant AppleScript. AppleEvents are the underlying mechanism that AppleScripts use to communicate between apps.
Copy link to clipboard
Copied
Ji John,
I don't think you had oversimplified anything. It looks rather sensefull. Reading over your answer, I came to taht conclusion (write all system file on a big do shell script command) but I was a bit horrified by the idea of dealing with such a terminal command. However as you suggest, I may call an applescript file with do script and the ampersand script and get all this stuff silently done.
I won't be at my office tomorrow, but I will try to give it a try in shortest terms.
Thanks a lot to Mark and you,
Loic
Copy link to clipboard
Copied
Sounds good! I don't think there is any reason to be afraid of big
shell scripts, the system ships with lots of them. For fun,
try reading /etc/rc.netboot (just an example).
If you needed to perform actions in InDesign after the shell scripts
were done, then that is where things begin to get tricky, with callbacks
and soforth. But as it stands, this looks straightforward. So good luck!
Copy link to clipboard
Copied
Hi all,
So I tried this little snippet:
Code ran from Indesign:
do shell script "arch -i386 osascript \"/Users/Loic/terminal.scpt\" &"
The called script contains these lines:
delay 10
tell application "Adobe InDesign CS5"
display dialog "allo"
end tell
Then Indesign crashes. If I run the script from the applescript editor, it works fine.
FYI
Loic
Still searching on my side 😐
Copy link to clipboard
Copied
Err...
It doesn't crash InDesign for me. CS5 7.0.4 MacOS 10.6.7.
It does, however, seem to take too long to display the dialog box and seems like it is going to hang.
But I am confused. I thought you had explained that you wanted to perform this sequential series of shell scripts without the script needing to do anything further in InDesign. InDesign would launch the scripts and return control to the user.
But that doesn't seem to be the case -- now you want InDesign to display a dialog box?
What does the crash report look like?
You could also try having the Finder display the dialog (or System Events?)
Copy link to clipboard
Copied
Hi John,
The code I sent was a snippet to get confident with the logic. Here is a shema of what I am trying to get.

I was feeling more cumfortable calling an applescript from shell script than writing all the command lines. My attempt is to have two scripts, one with Indesign actions and which calls the second script (working asynchronously from Indesign) that in return warns Indesign when he achieved its work.
The final alert within Indesign intends then to warn user that system operations have been done successfully.
Maybe Indesign wasn't crashing. It hanged for so long that I thought it did. However, as you noticed, it takes ages and Indesign is still unusable until then.
Is it clearer ?
Loic
Copy link to clipboard
Copied
Loic are you you don't just want an Applescript run script? I have no issues with this quick test… My main calling script…
tell application "Adobe InDesign CS2"
tell document 1
-- export stuff
end tell
my runOther()
end tell
on runOther()
set OtherScript to (path to desktop as text) & "RunScript.scpt" as alias
run script OtherScript with parameters {10, 20} -- just some delay values
end runOther
The called run script…
on run args
my zip(item 1 of args)
my curl(item 2 of args)
my alert()
end run
on zip(d)
delay d
tell application "Adobe InDesign CS2"
activate
display dialog "ZIpped…"
end tell
end zip
on curl(d)
delay d
tell application "Adobe InDesign CS2"
activate
display dialog "FTP…"
end tell
end curl
on alert()
tell application "Adobe InDesign CS2"
activate
display dialog "Done" giving up after 3
end tell
end alert
I can continue to work adding content etc. to the active document and just get interrupted for the dialogs…
Copy link to clipboard
Copied
Hi John,
Thanks a lot for your help and interest.
I did try run script and noticed that although Indesign was somehow usable, it was barely handleable. I mean that any work is slowed down, moving textframes is for example a pain. Once the called script has done its work Indesign gets back to 100% efficiency. Or could it be my machine only (too slow ?). Don't you have these kinds of delays with manipulation ?
So yes it's usable but quite useless in the meanwhile :S
That's why I was seduced by your ampersand solution on shell scripts. I am starting wondering if there is any valuable solution ![]()
I have seen that ran from applescript editor, run script works perfect. But it means saying to end users, ro run an indesign script, just leaves Indesign and run the script from the system
, not really acceptable.
Thanks anyway for your help in that matter.
Loic
Copy link to clipboard
Copied
I just read over a bit to put "do shell script" into background. Maybe this helps.
While Im asking a script guru: Is there a possibility to put a called javascript in background to script further on?
Im desperate struggeling calling a place dialog at a specific path, then pressing commnd+F to get into the spotlight-search-field within the open place-dialog and paste a string from clipboard.
All I get done is calling an external javascript which calls the dialog at a specific path, but then AS waits for JS to finish.
do shell script without waiting |Official Apple Support Communities
"do shell script "/bin/blah > /dev/null 2>&1 &"
The '> /dev/null' suppresses stdout; '2>&1' suppresses stderr (specifically, sends stderr to the same place as stdout), and the trailing '&' puts the command in the background.
Using this suffix will return control to your AppleScript immediately, leaving the shell process running in the background."
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more