I have an applescript that utilizes a named pipe and pipes data over to it. I have my script passing said data in a while loop, which is working, but I find that I am unable to stop the script manually without quitting the Script Editor program. I do not need to force quit.

Here is the relevant snippet of my script (d is a QT movie reference that is active and playing; aname is a valid POSIX path that specifies the location of the named pipe):

repeat while d is playing
    set currtime to (get current time of d) as string
    get currtime
    do shell script "echo " & currtime & " > " & aname
    delay 0.125
end repeat
  • 1
    There is an issue with applescript and pipes. I've posted a question about the problem here. This is my solution to your problem but alas it is not working as I expected... – Vic Aug 26 '15 at 17:41

So the following script will send the text to the pipe, in the background, and if the background job does not exit after a second it will kill it. This should stop the script from blocking...

echo $1 > $2 &

sleep 1

# Following is necessary. Seems to need it or
# job will not complete! Also seen at
#  http://stackoverflow.com/a/10736613/348694
echo "Checking for running jobs..."

kill %% >/dev/null 2>&1

if [ $? -eq 0 ] ; then
   echo "Taking too long. Killed..."
   exit 1

exit 0

You can launch it from AS like this...

set qstr to quoted form of (currtime as string)
   do shell script "/some/dir/topipe.sh " & qstr & " " & mypipe
on error
   display dialog "ERROR:....."
end try
|improve this answer|||||

Are you sure you have something at the other end of that named pipe actually accepting the data? "do shell script" will not exit until something actually tries to read from the pipe. If you want to work around this, you can use:

do shell script "sh -c \"echo " & currtime & " > " & aname & "\" &> /dev/null &"

This will keep spawning shells which will all wait until you actually use the pipe. Not really a great solution. Ideally you should have something waiting for data before you send anything to a named pipe, or spawn something to consume the data.

|improve this answer|||||

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .