3

I have to set up a bash script which will be in the autorun for all our users.

I can not set the terminal settings to close on "process complete". I can not 'KillAll' the terminals.

Does someone know an approach? I think the PID-solution (not parent pid) would be a nice way.

OS used is MacOS Sierra.

test.sh

#!bin/bash
currentUser=$(whoami)
mkdir -p ~/Desktop/Pdrive
mount_smbfs //server/UserData/$currentUser ~/Desktop/Pdrive


#pid=$$
#kill $pid
#exit 0
#kill -15 $$
#disown
#kill -9 $(ps -p $(ps -p $PPID -o ppid=) -o ppid=)
#osascript -e 'tell application "Terminal.app" to quit'
#pkill -f test.sh
exit
5
  • You are trying to kill all terminal sessions?
    – Luka
    Mar 16, 2017 at 13:47
  • 1
    Try this: osascript -e 'tell application "Terminal" to close first window' #to ask you before leaving osascript -e 'tell application "Terminal" to close first window' & exit #leave without asking. P.S Please do not use killall because killall does different things on different Unix versions.
    – Luka
    Mar 16, 2017 at 13:50
  • 1
    Thanks alot Luka, this is exactly what I was searching for
    – Sevi S.
    Mar 16, 2017 at 14:26
  • Luka: It would be best if you made your comment into an answer, so that the asker can mark it accepted; this will help future users find it.
    – dhag
    Mar 16, 2017 at 14:52
  • OK I did, now asker can accept it.
    – Luka
    Mar 16, 2017 at 16:29

2 Answers 2

1

Try this:

If you wish to be asked before leaving:

osascript -e 'tell application "Terminal" to close first window' 

Leave without asking:

osascript -e 'tell application "Terminal" to close first window' & exit

Please do not use killall because killall does different things on different Unix versions.

0

You could run your script in the current shell using source (also known as .):

. ./test.sh

This way, when you script calls exit, your shell will exit too. This should cause your terminal emulator to close as well.

This does not, however, work with Terminal from macOS with its default settings, but you could go to Preferences → Profiles → Shell → "When the shell exits" and choose "Close the window" or "Close if the shell exited cleanly".

1
  • Thanks for the input, I have my solution from @Luka 's answer. Since this is for multiple clients (including developers) I can not go and change terminal settings. Other users are not from the it environment, so I can not expect them to launch an sh command after logging in :) Thanks anyway
    – Sevi S.
    Mar 16, 2017 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.