2

So I'm looking at running lets say the following script

    #!/bin/bash/
    do
    echo "Starting script"
    osascript -e 'tell app "System Events" to display dialog "Currently script is running, please do not use computer"'
    do somecommands
    done

I would like the display to stay on the screen while the "do somecommands" is running in the background without terminating that display. Is this possible?

Thanks

1
  • You might want to look at macscripter.net Commented Feb 24, 2017 at 9:04

1 Answer 1

2

You can do it by running the osascript in the background like this:

#!/bin/bash/

echo "Starting script"
osascript -e 'tell app "System Events" to display dialog "Currently script is running, please do not use computer" with title "DIALOG TITLE"' &
# do other stuff

However, you will have 2 new problems - how to dismiss the dialog when you are finished and timeouts.

So, if you want to dismiss the dialog later, you will want to know its process id, so you should capture that after you start the background job like this:

osascript -e .... &
pid=$!
# Do some other stuff 
# kill the dialog
kill $pid

Unfortunately, that doesn't seem to make the dialog go away - maybe someone else can help with that.

UPD: to close previously opened window we can do following:

osascript -e 'tell application "System Events" to click button "Cancel" of window "DIALOG TITLE" of process "System Events"'

Secondly, if you are doing something time-consuming, the dialog will time out, so you may want to add a timeout like this for, say 100 seconds:

osascript -e 'tell app "System Events" to display dialog "Currently script is running, please do not use computer" giving up after (100)' &

Maybe that is the better way to do it anyway, run a loop and if the timeout expires and you are still busy, redisplay the dialog and if you are finished don't re-display the dialog - then you don't have the problem of how to make it go away at the end.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.