Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

On Linux and Mac OS X, is there a kill or killall command that can let the app ask for unsaved document before exiting, kind of like asking the app to quit, or clicking on the "close" button of the window.

For example, type somecommand TextEdit on Mac and TextEdit will ask you if you want to save the unsaved document.

share|improve this question
add comment

6 Answers

That's up to how the individual program responds to signals. If you do a kill with a 15 (SIGTERM) a program is supposed to do cleanup then exit. If, what and how are another matter.

share|improve this answer
add comment

For OS-X, try the script in Quit applications politely from the command line from MacOSXHints.com. You can tell the target app whether or not to save its open files. OS-X-specific, though - it uses AppleScript.

share|improve this answer
add comment

Doesn't look like it, though you can look check out the various kill signals available and try them out. I tried a few but they all seem to just interrupt the process instead of sending a quit signal.

share|improve this answer
add comment

I think it depends on the application, but kill -2, -3 or -15 might be what you are looking for...

share|improve this answer
    
You can run man 5 signals to see what those numbers mean –  Daenyth Jun 30 '10 at 20:44
add comment

Mac:

osascript -e 'tell app "TextEdit" to quit'

If you need to specify the app as an argument,

osascript -e 'on run args
  tell app (item 1 of args) to quit
end run' TextEdit

(Or save the quoted script in a file and osascriptscript appname.)

share|improve this answer
add comment

Signals that terminate an application aren't meant to allow the application any further user interaction. Either the user is no longer available (the HUP signal, whose original meaning was that the user was connected to the computer through a modem and the phone died), or the user doesn't want to be bothered (the default TERM signal and its more violent siblings QUIT and KILL). Many applications will try to save unsaved work somewhere if they receive the HUP signal, though.

A different option for Linux (and other unices) is to send a notification to the window, rather than the process: the _NET_CLOSE_WINDOW message tells an application to get rid of a specific window gracefully. You can send this message from the command line with wmctrl, e.g., wmctrl -c WINDOW_TITLE_SUBSTRING. Unfortunately, not all applications support this.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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