AppleScript hanging on problematic end device

Hey folks!
Using Bomes to send AppleScript: do shell script “curl……” to my Panasonic PTZs. Everything works great except!

One if my ptz cams is having some network connectivity issue which I need to sort out. BUT- I’ve noticed in Bomes that when I send an AppleScript curl to that problematic device, the response takes too long, and backs up all my other AppleScript translators… then once Bomes decides there’s an issue with that end device, it moves past it, then releases all those backed up translators at once… is there any way to change the behavior to where Bomes isn’t waiting on a response from that device in order to continue processing all my other translators?

Hi,

Although I’ve done limited AppleScript programming, I will try to help you. I believe indeed that Bome MIDI Translator Pro may be waiting for your AppleScript to complete before moving on. I have to check into this further but believe it does this as in many cases AppleScript will return a global variable which Bome MIDI Translator Pro would need to process prior to moving on. If your AppleScript does not return any variables, then there shouldn’t be any reason to wait for completion.

Maybe a good workaround would be to have an outgoing action of calling a shell script task putting it in the background as an outgoing action to execute your curl statement instead of using an AppleScript outgoing action?

image

Steve Caldwell
Bome Customer Care


Also available for paid consulting services: bome@sniz.biz

Just to clarify: in MIDI Translator Pro, all AppleScript actions are blocking, i.e. the next AppleScript action waits for completion of the current AppleScript action. If an AppleScript action takes a long time, MT Pro will wait for it.

There are a number of (good) reasons for this, mainly that MT Pro keeps one AppleScript execution environment in memory so that whenever an AppleScript is to be executed, it happens fast. Otherwise, every AppleScript action would need to first set up the AppleScript environment, which takes a long time, especially when running time sensitive scripts.

In your case, you seem to be calling curl from your AppleScript. The time when that script terminates is not determined by MIDI Translator Pro or AppleScript, but by the curl process when it is done (i.e. when it terminates). So I suggest to set a low timeout in your call to curl. I see this option in the curl manual:

--connect-timeout 0.5

which will wait at maximum half a second to connect to the PTZ camera.

Alternatively or additionally, there is probably a way in AppleScript to call curl and not wait for its termination. You will have to look this up on your own, depending on how your script is set up.

Of course, you can also use Steve’s suggestion to use MT Pro’s Execute File outgoing action and call a shell script movecamera.sh which just calls curl without waiting for it. Because you can use it as general replacement for curl, I’d name it curl_nowait.sh:

curl_nowait.sh:

#!/bin/sh
nohup curl "$@" &

The & at the end will execute the command in background, while the nohup command will prevent the shell to wait for termination of its background processes.

You can also replace the call to curl in your AppleScript with a call to curl_nowait.sh (with same parameters).

I hope that gives you some ideas how to improve your situation.