18 December 2012, 09:32
I have four accounts setup on Messages (a.k.a. the erstwhile iChat). Whenever my MacBook Pro wakes from sleep mode, all log back in automatically apart from one: Yahoo Instant Messenger. I don’t know why it remains offline. Although I don’t use AOL IM, I read somewhere that it too can be irritating in this way.
I worked-out the quickest and most efficient way to get it back online was to right-click the Dock icon (or the Messages icon at the top right of the desktop), then take all accounts offline by clicking the menu option, then immediately click the “Available” menu option to bring them all back online. This way I could avoid opening Messages to do so, which takes longer.
There’s an automated solution, however, involving crontab and a little Applescript that periodically tells Messages to put all accounts online (if they’re already online then the instruction’s simply ignored). Crontab lets you schedule tasks to run periodically in the background. It’s 100% Unix and was superseded by launchd some years ago, but crontab is significantly simpler to setup than a launchd service, and frankly works just as well in this situation.
Here are the steps necessary:
1. Ensure Messages starts at login by right-clicking its Dock icon and selecting the option. Remember that, in OS X Mountain Lion, apps not used for a while will appear to quit automatically, but don’t worry — these steps take that into account.
2. Open a Terminal window. You’ll find this in the Utilities folder of the Applications list within Finder.
3. At the command-line prompt, type crontab -e
4. This will open your (probably) empty crontab file within the vi text editor. Hit I to switch to insert mode, so you can type text. Then copy and paste the following, which is all one line but which I’ve split across two to ensure it fits on the page:
*/15 * * * * osascript -e 'tell application "System Events" to tell application "Messages" to log in'
Note that if you copy and paste the line, the quotation/single quote marks might be “curly”, depending on which browser you use. This will stop the command working. You might need to delete the quotes, then type them again using your keyboard.
The command causes the AppleScript we specify to run every 15 minutes, which seems reasonable to me because I became a little wary that any more frequent running of the command might impact battery life of my MacBook. But you can change the 15 at the start of the line to any other value, such as 5 minutes.
5. Hit Escape, then type :wq which will save the file and quit the editor.
That’s it. You can test it however you wish. Perhaps you might want to take all your accounts offline, then wait up to 15 minutes to find that you’re back online automatically in the background.
To undo, just repeat the steps to open your crontab file and delete the line you entered.
There are two drawbacks I can see, as follows:
1. If you access any of the chat accounts from another computer/device (like an iPad) while your computer is up and running, you’ll be logged out of that device every 15 minutes by this script running on your Mac if the IM account doesn’t allow multiple logins (Yahoo doesn’t). I’m not sure how to overcome this outside of a horrendously complex AppleScript that’ll probably fail anyway.
2. As mentioned earlier, Mountain Lion introduced automatic termination of apps that haven’t been used for a while. While Messages might appear to quit, it actually sticks around in memory. But sometimes it’s lost when your computer wakes from sleep mode. The script takes this into account because it will start Messages if it isn’t already in memory, but there’s the potential that — when you wake your computer from sleep mode — you’ll be offline on your errant Yahoo or AIM account for up to 15 minutes if you use the script as-is. The easiest way to fix this is to bring the time period for running the script down to 5 minutes or so.
Commenting is closed for this article.