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.

link|improve this question

67% accept rate
feedback

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.

link|improve this answer
feedback

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.

link|improve this answer
feedback

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.

link|improve this answer
feedback

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

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

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.)

link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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