V.K. asks: "why do you need to do this before login?" And macwiz1220 suggests including in Login Items an app created by AppleScript that launches Terminal and runs the diskutil command.
When I create and run such an app at login, I encounter problems with Terminal, which is why I thought to run an .sh script at startup. But if we can debug the problems with Terminal, then I won't have to venture into the more complex solutions offered by gbullman and Barney-15E. Terminal problems:
(1) When Terminal prefs for Settings>Shell are set this way:
(a) When the shell exits: Close the window.
(b) Prompt before closing: Never
then the result is: Terminal is launched and exits quickly, but the "Untitled" volume is not unmounted.
(2) When Terminal prefs for Settings>Shell are set this way:
(a) When the shell exits: Close the window if the shell exited cleanly
(b) Prompt before closing: Never
then again the result is: Terminal is launched and exits quickly, but the "Untitled" volume is not unmounted.
(3) When Terminal prefs for Settings>Shell are set this way:
(a) When the shell exits: Don't close the window
(b) Prompt before closing: Always
then after invoking the script, Terminal properly unmounts "Untitled" and presents a dialog: "You have 2 windows with running processes. Do you want to review these windows before quitting?" Here are the two Terminal windows:
ℹ an echo of the cmd "/usr/sbin/diskutil unmount force disk0s3" followed by a report on return: "Volume on disk0s3 force unmounted." I don't want the user to have to see this and close the window.
(ii) a fresh Terminal session, no commands entered. I also don't want the user to have to deal with this.
How can I get Terminal to properly unmount the object, and shut down without demanding user interaction?
P.S. what is an O.P.?