Platypus icon indicating copy to clipboard operation
Platypus copied to clipboard

system unresponsive during script execution of Status Menu app

Open michaelcinquin opened this issue 6 years ago • 8 comments

Hi

during the execution of the script called by a Status Menu App, the system becomes unresponsive. User input in Terminal becomes impossible, one has to ssh into the box to kill the script.

Steps to reproduce:

  • create a one line ~/sleep.sh : sleep 10
  • create a Platypus Shell script with interface "Status Menu"
  • run app --> system is unresponsive for 10 seconds

The problem doesn't happen with other user interfaces.

This is using Platypus 5.2 1008, running on 10.12.6

hope this is something you could fix?

michaelcinquin avatar May 30 '18 07:05 michaelcinquin

Hello there and thank you very much for the donation!

The problem here is that the script is immediately run when the status item is pressed. The Platypus app then waits for the script to finish executing on the main thread, parses the output and presents the menu. If the script locks up or goes to sleep, the app just merrily waits for it to finish none the less, which locks up the interface.

Now, this wouldn't normally affect the rest of the system UI but Apple implements Status Items in such a way that they are "part of the interface" and can therefore lock up the main system UI thread.

There are two solutions I see to this:

a) Add a hard timeout limit for script execution (a few seconds), after which the script process is killed and no menu shown (or maybe a timeout error message)

b) It may be possible to try to update the menu asynchronously, i.e. launch the script, show the empty menu, parse output from script in background and then add menu items on the main thread as the script output is received and parsed. This is likely to be tricky to do in a reliable way. However, it's something worth looking into. Some Apple-provided SystemUIServer menus (e.g. Time Machine) do update their contents dynamically. The Status Menu output mode has always been a bit flaky due to the special nature of the Status Item API, but maybe there are ways around it.

What kind of scripts are you running that take such a long time to execute? For long-running processes, Status Menu output mode is unlikely to be what you want.

sveinbjornt avatar Jun 01 '18 12:06 sveinbjornt

hello,

thanks for the reply. I'm running scripts which do network requests to show status, some of which can take a bit of time. Status menu output is really what I'm after.

Would it be possible to send a notification from a background thread to the main thread after the script exits, and then after it has received the notification the main thread would read the output of the script. In the meanwhile, the main thread could show "processing…" or something like this?

michaelcinquin avatar Jun 04 '18 12:06 michaelcinquin

I just threw together a test project which shows that this is definitely possible. This feature is now on the Platypus 5.3 roadmap.

Would you like me to send you a new ScriptExec binary with this feature as soon as it's working reliably? It may be months before I release another version of Platypus.

sveinbjornt avatar Jun 06 '18 16:06 sveinbjornt

perfect! Sure, I would love to receive a new ScriptExec binary. Many thanks

michaelcinquin avatar Jun 08 '18 07:06 michaelcinquin

What is the status on this? Is there a special way to write the script to make the menu bar responsive?

m0ose avatar Jan 21 '22 22:01 m0ose

I'm afraid you'll have to wait for Platypus 5.3.

sveinbjornt avatar Jan 22 '22 14:01 sveinbjornt

I'm afraid you'll have to wait for Platypus 5.3.

Did you make a newer version of Platypus. It seems we've been at Platypus 5.3 for several years already

huyz avatar Jun 12 '22 17:06 huyz

Can I add an exit button?

akwangl avatar Oct 17 '23 09:10 akwangl