How to auto-close terminal after script finishes?

Discussion in 'Mac Basics and Help' started by mishka00, Nov 18, 2008.

  1. mishka00 macrumors newbie

    Joined:
    Nov 17, 2008
    #1
    Hello!

    I've got a script that I run to unmount all devices as follows:

    Code:
    #!/bin/sh
    osascript -e 'tell application "Finder" to eject (disks where free space * 0)'
    When I double-click it, it launches in a terminal window and displays the following:

    Code:
    MacbookPro:~ Mishka00$ /Users/Mishka00/Scripts/unmount_all ; exit;
    logout
    
    [Process completed]
    
    The devices get unmounted ok, that's fine, but the terminal window remains open. I'd like it to automatically close (and the terminal to exit as well, for that matter).

    Please help. Thanks.
     
  2. belvdr macrumors 601

    Joined:
    Aug 15, 2005
    #2
    Think that's a Terminal preference thing. I guess you could do a ps and search for Terminal's PID and kill it, however, if a user has more than one Terminal, you'd have to search for the parent PID in your script, then kill it later on. If this is just for you, then it's not that important: just change Terminal's pref's to auto-close.
     
  3. MacsRgr8 macrumors 604

    MacsRgr8

    Joined:
    Sep 8, 2002
    Location:
    The Netherlands
    #3
    What about ending the script with "killall Terminal"?
     
  4. macospimp macrumors newbie

    macospimp

    Joined:
    Nov 18, 2008
    Location:
    San Jose, California
    #4
    "killall Terminal" will do the trick
     
  5. r1ch4rd macrumors 6502a

    r1ch4rd

    Joined:
    Aug 5, 2005
    Location:
    Manchester UK
    #5
    You just need to be careful because that will close all Terminal windows and it won't close them cleanly either.
     
  6. MacsRgr8 macrumors 604

    MacsRgr8

    Joined:
    Sep 8, 2002
    Location:
    The Netherlands
    #6
    The way I like it... shutting down Windows dirty...
     
  7. mishka00 thread starter macrumors newbie

    Joined:
    Nov 17, 2008
    #7
    I tried that but got a message
    "No matching processes belonging to you were found"
    which is probably related to the user permissions or some such. As I'm just a recent convert from Windoze, I didn't research this much, but I did find an alternative way to kill the terminal from the script which works flawlessly:

    Thanks for the help, anyway.
     

Share This Page