Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Quit Mail.app remotely in a nice manner UNIX
I like to log in remotely (over ssh) to my machine for quick email checks using pine or mutt, but I usually leave Mail.app running when leaving home.

The problem is that with both mail programs running at once, they would compete for the IMAP connection and complain. So, I wanted a simple way to quickly & gracefully quit Mail.app remotely. I know I could use killall Mail, but I wanted something that would save any mail being composed and such, so ApplesSript was the answer.

I ended up adding the following two lines to my .profile (I like .profile for config better than .bash_login because it seems to get used by X11 and Terminal.app). It's just a simple inline Applescript:

# make it easy to remotely quit Mail.app
alias quitmail='osascript -e "quit application "Mail" saving yes"'
Please enter any better ideas in the comments ... I'm open to better approaches!
    •    
  • Currently 2.60 / 5
  You rated: 4 / 5 (5 votes cast)
 
[12,801 views]  

Quit Mail.app remotely in a nice manner | 17 comments | Create New Account
Click here to return to the 'Quit Mail.app remotely in a nice manner' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Quit Mail.app remotely in a nice manner
Authored by: steresi on Jun 15, '04 11:31:47AM

I tried adding the alias above to my .bash_login, adapting it for Microsoft Entourage, but I received the following cryptic error:

## Component Manager: attempting to find symbols in a component alias of type (imdc/MP42/MSFT)
osascript: arguments following program will be ignored.
17:26: execution error: The variable Microsoft is not defined. (-2753)

The problem was the nested double quotes needed to be escaped with backslashes. So this is the command that worked for me:

alias quitmail='osascript -e "quit application \"Microsoft Entourage\" saving yes"'

Scott
--
www.teresi.us



[ Reply to This | # ]
correction
Authored by: alanb1979 on Jun 15, '04 11:40:33AM

You're right ... I actually had to use the following. I think I just mis-copied this in my original post.

alias quitmail='osascript -e "quit application \"Mail\" saving yes"'

---
hiedy hoo

[ Reply to This | # ]

correction
Authored by: alanb1979 on Jun 15, '04 11:44:40AM

Daaaa ... the HTML-version of the posting script keeps removing my backslashes, even within <code></code> tags.

Here's the correct one:
alias quitmail='osascript -e "quit application \"Mail\" saving yes"'

---
hiedy hoo



[ Reply to This | # ]
Similar thing, with a more general script
Authored by: ZZamboni on Jun 15, '04 01:57:06PM
I have written a script called "quit":

#!/bin/sh
osascript -e "tell application \"$1\" to quit"
This uses its first argument as the name of the application. Save this somewhere in you $PATH ($HOME/bin/quit, for example), make it executable (chmod a+rx $HOME/bin/quit) and then you can quit most Applescriptable applications:
quit Mail
quit iTunes
etc.

[ Reply to This | # ]
Similar thing, with a more general script
Authored by: Dale Mox on Jun 15, '04 05:40:26PM

Correction:

#!/bin/sh
osascript -e "tell application \"$1\" to quit"



[ Reply to This | # ]
Similar thing, with a more general script
Authored by: craig on Jun 15, '04 05:40:37PM

This doesn't work for me. When I enter "quit TextEdit," I get the following error:

17:25: execution error: The variable TextEdit is not defined. (-2753)



[ Reply to This | # ]
Similar thing, with a more general script
Authored by: craig on Jun 15, '04 05:42:10PM

Thanks for the correction. Now it works.



[ Reply to This | # ]
Quit Mail.app remotely in a nice manner
Authored by: billabOng on Jun 15, '04 02:30:52PM

I ssh in and use 'kill -15 <pid>'. Seems to work fine so far.



[ Reply to This | # ]
any tech reason not to kill or killall?
Authored by: alanb1979 on Jun 15, '04 05:31:55PM

I used to do this too, but somehow it bothered me ... does anyone know some technical reasons that would make the AppleScript version more desireable?

---
hiedy hoo



[ Reply to This | # ]
any tech reason not to kill or killall?
Authored by: billabOng on Jun 15, '04 06:12:18PM

From the kill manpage (on my NetBSD box.. OSX doesn't seem to have it):

15 TERM (software termination signal)

AFAIK, this means.. Quit gracefully.

No need to use killall to kill 1 process.



[ Reply to This | # ]
any tech reason not to kill or killall?
Authored by: BananaFish on Jun 16, '04 04:16:06AM

I think the advantage of using killall instead of kill is that you can kill a process by name and not by PID. So, instead of having to figure out what PID Mail is using, you can simply run killall Mail.

One disadvantage to using killall might be that, if you have more than one user logged in through Fast User Switching, you could run the risk of killing off more than one instance of Mail. The killall man page states: "By default, it will send a TERM signal to all processes with a real UID identical to the caller of killall that match the name procname. The super-user is allowed to kill any process." In other words, as long as you're shelled in as yourself and you just run killall as yourself and not as root, you should be fine. I tried it out on my own system and it worked as the man page describes.

My OS X installation has a man page for kill, by the way.

---
I'm interesting
You think I'm interesting
Like the apocalypse

[ Reply to This | # ]

Quit Mail.app remotely in a nice manner
Authored by: phripley on Jun 15, '04 06:45:29PM

The poster's method has the advantage of allowing unsaved work be be saved. Or am I missing something?



[ Reply to This | # ]
Quit Mail.app remotely in a nice manner
Authored by: gshenaut on Jun 15, '04 03:26:53PM

I'm confused. I thought that a major point of IMAP was that it would allow more than one connection at a time. How does mail.app complain about this?

Greg Shenaut



[ Reply to This | # ]
Quit Mail.app remotely in a nice manner
Authored by: alanb1979 on Jun 15, '04 05:27:35PM

Actually, it's mostly pine that complains. It says something about failing to get a mailbox lock and keeps having to re-open the connection.

I have both pine and Mail.app auto-checking for new mail every 5 minutes if they are running.

Mail.app doesn't "complain," it just doesn't always correctly update the unread and replied-to icons in my inbox.

---
hiedy hoo



[ Reply to This | # ]
Quit Mail.app remotely in a nice manner
Authored by: BananaFish on Jun 16, '04 04:43:11AM

The point of IMAP is really to be able to store information in a central location and access it from multiple locations. My sense about whether or not you can access that central store from more than one place simultaneously has more to do with the client applications that you're running than it does IMAP.

My situation is similar to the original poster's in that I use Mail.app when I'm at home, but I use Ximian Evolution at work when I'm in the office and pine when I'm out in the field for work. Of the three mail applications, only Mail.app seems to tolerate simultaneous IMAP connections. Evolution can be sketchy at times, and I just get in the habit of restarting pine on a regular basis because the inbox becomes read only and then I don't see any new mail that comes in.

There is apparently a certain amount of file locking that takes place with IMAP connections. I used pine pretty exclusively for a while at work until we implemented phpGroupWare. We have phpGroupWare configured to use IMAP for authentication and, whenever I would log into phpGroupWare (or possibly do anything) my pine session would become read only. I still have similar problems with Evolution, but I can simply force a mail check and everything is OK. I don't have any issues using Mail.app and phpGroupWare simultaneously.

---
I'm interesting
You think I'm interesting
Like the apocalypse

[ Reply to This | # ]

Quit Mail.app remotely in a nice manner
Authored by: rajulkabir on Jun 29, '04 06:37:09AM

It depends on the IMAP server in use. Some can handle multiple simultaneous accesses and others can't. Notably, UW-IMAPd does not deal well with it, while Courier does.

After switching to Courier, I could hit 'delete' on a message in Pine and within seconds that same message would go gray in my Apple Mail window.



[ Reply to This | # ]
Quit Mail.app remotely in a nice manner
Authored by: david-bo on Jun 16, '04 05:41:23AM

Why not simply pause Mail.app and then resume it later?

pause killall -STOP Mail.app

continue killall -CONT Mail.app


---
http://www.google.com/search?as_q=%22Authored+by%3A+david-bo%22&num=10&hl=en&ie=ISO-8859-1&btnG=



[ Reply to This | # ]