0

I have a bash script that I have turned into a standalone macOS app (i.e. I created a folder Script.app which contains subfolders Contents and MacOS and in the folder MacOS resides my bash script). If I open the app the bash script runs and after the successful run, the app closes immediately.

I would like the app to remain open and run another bash script upon quitting the app. Or, if this cannot be done, perform some Finder action upon quitting (more precisely unmounting a Volume).

  • Just create a second app to unmount the volume again. Or use AppleScript (but then you also have to handle situations where a user unmounts by ejecting the drive in Finder) – nohillside Dec 10 '19 at 17:40
  • Sure, I could create a second app, but that's not the functionality I would like to achieve. You write Or use apple script. To do what exactly? – 220284 Dec 10 '19 at 17:48
  • To implement the functionality you want :-) – nohillside Dec 10 '19 at 17:50
  • I don't know how to use AppleScript to keep the app open after the bash script has exited (and it looks to me like there is no such functionality in Apple Script). My guess would be that I rather have to modify the app itself. – 220284 Dec 10 '19 at 17:58
  • 1
    You'll need to add a quit handler, have a look at idle and quit Handlers for Stay-Open Applications. – user3439894 Dec 10 '19 at 18:37
1

Gathering what's above in the comments, here's what works: Use Script Editor to write a script containing

do shell script "complete_path_to_start_script"
on quit
    do shell script "complete_path_to_quit_script"
    continue quit
end quit

Use Script Editor to export the script as a standalone app which remains open after the start script has terminated. This option can be selected in a checkbox.

| improve this answer | |

You must log in to answer this question.

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