Using AppleScript to restore missing functionality from iChat to Messages in OS X 10.9.x Mavericks

Those of you who have run previous versions of OS X and are now running Mavericks may have noticed that the Messages client lacks quite a bit of the functionality of the iChat program that was included with earlier versions, and in particular the ability to take actions based on certain events.  However it is possible to restore some of that functionality using AppleScript.  Here’s a thumbnail overview of how to get started.

First, open the ~/Library/Application Scripts/com.apple.iChat/ directory and make a copy of the file Speak Events.applescript (you can temporarily copy it to another directory).  Rename the copy to something else (we used Custom Sounds.applescript for this demo) and move the copy back into the  ~/Library/Application Scripts/com.apple.iChat/ directory.

Open the Custom Sounds.applescript file in the AppleScript Editor (it’s in the Utilities folder inside your Applications folder) and make the changes shown below.  When you get through with your edits and you have compiled them you will see something like this:

Custom Sounds AppleScript

The easiest way to do this is to select all the existing AppleScript code, delete it, and replace it with the following:

using terms from application "Messages"
	on message received from theBuddy
		set qHandle to handle of theBuddy
		# do shell script "echo " & qHandle & " >> ~/Downloads/buddies.txt"
		if qHandle is equal to "someuser@somechatserver.com" then
			set playsound to POSIX path of ("/System/Library/Sounds/Pop.aiff")
		else if qHandle is equal to "someotheruser@somechatserver.com" then
			set playsound to POSIX path of ("/System/Library/Sounds/Frog.aiff")
		else
			set playsound to POSIX path of ("/System/Library/Sounds/Glass.aiff")
		end if
		do shell script ("afplay " & playsound & " > /dev/null 2>&1 &")
	end message received
	
	on active chat message received from theBuddy
		set qHandle to handle of theBuddy
		# do shell script "echo " & qHandle & " >> ~/Downloads/buddies.txt"
		if qHandle is equal to "someuser@somechatserver.com" then
			set playsound to POSIX path of ("/System/Library/Sounds/Pop.aiff")
		else if qHandle is equal to "someotheruser@somechatserver.com" then
			set playsound to POSIX path of ("/System/Library/Sounds/Frog.aiff")
		else
			set playsound to POSIX path of ("/System/Library/Sounds/Glass.aiff")
		end if
		do shell script ("afplay " & playsound & " > /dev/null 2>&1 &")
	end active chat message received
	
	# The following are unused but need to be defined to avoid an error
	
	on message sent theMessage with eventDescription
	end message sent
	
	on chat room message received with eventDescription
	end chat room message received
	
	on addressed message received theMessage from theBuddy for theChat with eventDescription
	end addressed message received
	
	on received text invitation with eventDescription
	end received text invitation
	
	on received audio invitation theText from theBuddy for theChat with eventDescription
	end received audio invitation
	
	on received video invitation theText from theBuddy for theChat with eventDescription
	end received video invitation
	
	on received local screen sharing invitation from theBuddy for theChat with eventDescription
	end received local screen sharing invitation
	
	on buddy authorization requested with eventDescription
	end buddy authorization requested
	
	on addressed chat room message received with eventDescription
	end addressed chat room message received
	
	on received remote screen sharing invitation with eventDescription
	end received remote screen sharing invitation
	
	on login finished with eventDescription
	end login finished
	
	on logout finished with eventDescription
	end logout finished
	
	on buddy became available with eventDescription
	end buddy became available
	
	on buddy became unavailable with eventDescription
	end buddy became unavailable
	
	on received file transfer invitation theFileTransfer with eventDescription
	end received file transfer invitation
	
	on av chat started with eventDescription
	end av chat started
	
	on av chat ended with eventDescription
	end av chat ended
	
	on completed file transfer with eventDescription
	end completed file transfer
	
end using terms from

You may wonder why we said to copy and open the copy of an existing file if we were just going to replace everything; it turns out that if you don’t do that the AppleScript editor seems to save the file in some format that Messages doesn’t recognize.

The edits you will need to change are these, in both the on message received… and on active chat message received… sections (make the same edits in both sections, otherwise it may not work as you expect):

		# do shell script "echo " & qHandle & " >> ~/Downloads/buddies.txt"

Uncomment these lines at first to discover the “handles” that are being sent when each buddy sends you an instant message – each one will produce a line in the file buddies.txt in your Downloads directory (you can use another directory and filename if you prefer). Normally they will be in a form like “username@server” which in some cases (particularly with Google users) might even be the same as their email address. Once a buddy has sent you a message, you can look in the file to see what their “handle” is. Then you can set up the conditions, like so:

		if qHandle is equal to "someuser@somechatserver.com" then
			set playsound to POSIX path of ("/System/Library/Sounds/Pop.aiff")
		else if qHandle is equal to "someotheruser@somechatserver.com" then
			set playsound to POSIX path of ("/System/Library/Sounds/Frog.aiff")
		else
			set playsound to POSIX path of ("/System/Library/Sounds/Glass.aiff")
		end if

Replace “someuser@somechatserver.com” and “someotheruser@somechatserver.com” with valid “handles”. The sounds can be whatever you want but they must be in .aiff file format – here we have used the standard sounds found in /System/Library/Sounds/ but there is no reason you can’t use other sounds or even custom .aiff files. The “else” condition specifies the default sound that will be played for incoming messages from buddies not specified in the other conditions. You can add as many “else if” conditions as you need, depending on whether you want to have distinctive sounds for additional buddies.

Don’t forget to comment the “do shell script …” lines back out once you have received all the “handles” that are important to you, otherwise that file will continue to grow with each received message, which is why we suggest putting it in your Downloads folder where you are more likely to notice it.

Finally to get Messages to use these sounds open its Preferences and select your new AppleScript file at the bottom of the panel:

Messages Preferences

Note that not only have we selected the Applescript, but we changed the default Message received sound to Tink, which is a very quiet sound – the reason is that while you can turn off all sounds in Messages, you can’t make the default Message received sound “nothing”. So when a message arrives, it will play both the “Tink” sound AND the sound you have selected in your AppleScript. We suppose you could use an audio editor (such as Audacity) to create an .aiff file with no sound in it, if even the Tink sound bothers you, or if that’s too much work you can download and unzip this one (place the resulting Silence.aiff file in the /System/Library/Sounds/ folder, and after doing that you’ll need to close and reopen the Messages application before you can select it as the Message received sound).

Obviously there are many other possibilities, both for adding custom sounds to other Message events and for taking additional or different actions. For example, if you looked at the Speak Events.applescript file that we had you copy at the start of this, you would see that it’s possible to have incoming messages be read aloud to you. Also, at least in theory it’s possible to select the buddy based on something other than the “handle” – if you go into the AppleScript Editor, File menu, and Open Dictionary, then scroll down to “Messages” and choose it, and then select “Messages Suite” and “buddy” you will see the screen shown here:

Messages Buddy options

You should be able to use the buddy “name” instead of the “handle”, but that would not work for us for some reason and generated an error popup. And note that to use some of these options you must have a “contacts card” (Address Book entry) for that buddy, with the selected field filled in.

By the way, rather that have two identical blocks of script under the on message received… and on active chat message received… sections, you could instead use a single subroutine, in this case named custom_notify, where the start of the script would be changed to look like this:

using terms from application "Messages"
	on message received from theBuddy
		custom_notify(theBuddy)
	end message received
	
	on active chat message received from theBuddy
		custom_notify(theBuddy)
	end active chat message received
	
	# The following are unused but need to be defined to avoid an error

(…the rest of the original script continues here…)

And then at the very end of the script (below the end using terms from line), you could define the custom_notify subroutine, which receives the single variable theBuddy:

on custom_notify(theBuddy)
	set qHandle to handle of theBuddy
	# do shell script "echo " & qHandle & " >> ~/Downloads/buddies.txt"
	if qHandle is equal to "someuser@somechatserver.com" then
		set playsound to POSIX path of ("/System/Library/Sounds/Pop.aiff")
	else if qHandle is equal to "someotheruser@somechatserver.com" then
		set playsound to POSIX path of ("/System/Library/Sounds/Frog.aiff")
	else
		set playsound to POSIX path of ("/System/Library/Sounds/Glass.aiff")
	end if
	do shell script ("afplay " & playsound & " > /dev/null 2>&1 &")
end custom_notify

This is just a quick overview to get you started but the idea is that by using AppleScript you should be able to restore the functionality of any “missing” iChat triggers that are important to you, and maybe even do a few things that iChat wouldn’t. If you come up with any useful AppleScript snippets or “recipes”, please feel free to post them in the comments section, so that others might benefit from your cleverness.

Related:
Buddy online notification in Messages (OS X Mavericks) (Too busy to…)
Send SMS to Messages and run commands with AppleScript Apps (Macworld)

Link: 20 Great Terminal Replacements for GUI Applications (Linux)

We’re not big command line fans, but still we occasionally find ourselves wishing that we could do some particular thing from a Linux command line that we would normally do from a GUI-based application, either because we’re on a server with no desktop or because we are remotely accessing a system.  But, we know there are those of you who love using your computer as if it were still the 1980’s.  So if, for whatever reason, you find yourself at the Linux command line, here is a list of 20 applications that might be useful to you.  There might even be a few here you don’t already know about!

20 Great Terminal Replacements for GUI Applications (TuxArena)

Anti-Gravity is a real thing!

Nobody’s going to attach much credibility to anything we post today, so with that in mind, here are links to three articles, only two of which are intended to be taken seriously.  Can you guess which ones?

Antimatter Gravitational Fields: Are we on the Cusp of ‘Anti-gravity Technology’? (From Quarks to Quasars)
Boeing Admitted Testing Anti-Gravity 12 Years Ago (Humans Are Free)
Shocking anti gravity device showed to Public… (Flying Rumor)

Be careful if you start researching subjects like anti-gravity. One of our editors started reading an anti-gravity research compilation, and he said that the problem with it was that he just couldn’t put it down!

Link: Day-O review: Me say day on the Mac’s menu bar

 As someone who has a regular schedule of weekly meetings and appointments—work meetings, after-school sports for my kids, and so on—it’s always helpful when someone who wants to schedule a meeting with me mentions the day along with the proposed date and time. For example, when I’m asked if I’m available on May 6 at 3 p.m., I have to look at my calendar; but if I know that May 6 is a Tuesday, I can immediately reply that I can’t do meetings after 3 p.m.

Day-O

Day-O’s calendar display

Which brings me to my biggest gripe about OS X’s Date & Time menu-bar display (enabled in the Date & Time pane of System Preferences): It shows you only the current date and time. There’s no option to display, say, a monthly calendar when you click in the menu bar. Sometimes I’m on the phone or writing an email to set up a meeting, and I’d like to know what day of the week a proposed date falls on—since I’m no calendar savant, I need to look it up.

Full article here:
Day-O review: Me say day on the Mac’s menu bar (Macworld)

What we like about this little program is that you can customize the date display exactly to your liking. For example, if you want to see everything at a glance with no abbreviations, you could use the Date & Time format string EEEE, MMMM d, y h:mm:ss a z which produces this:
Day-O custom date formatUnfortunately, it won’t flash red or sound a warning that it’s April Fools Day, and that your friends or co-workers might try to prank you!

Link: How to set up automatic filesystem checks and repair on Linux

One of the most important tasks in Linux administration is to check the integrity of the filesystem. The Linux filesystem can be damaged under various circumstances, e.g., system crash, power loss, disconnected disk, accidentally overwritten i-node, etc. Thus it is a good idea to check the integrity of the filesystem regularly to minimize the risk of filesystem corruption. When it comes to checking and repairing Linux filesystem, fsck is a useful tool.

In this tutorial, I am going to describe how to set up automatic filesystem checks with fsck tool.

Full article here:
How to set up automatic filesystem checks and repair on Linux (Xmodulo)

Link: Merge Files of Different Formats Into One File Online With MergeFil.es

Mergefil.es  is a free online file merger that lets you merge or combine multiple files into one single file. This free online file merger can combine multiple files of different formats into one single PDF, MS Word, or MS Excel document.

It supports variety of file formats, like: PDF, MS Word, MS Excel, Images, HTML and TXT. It lets you order the file placement, by moving them, upward or downward. Not only that, this freeware has the ability to compress the file as well.

Full article here:
Merge Files of Different Formats Into One File Online With MergeFil.es (I Love Free Software)
Related:
MergeFil.es Lets You Combine Files of Different Formats into One Unified Document (TechNorms)
[Web] Merge multiple files of different formats with MergeFil.es (dotTech)

Link: Pelican: A fast blog/CMS for the Raspberry Pi

… I wanted blogging software to run on the Raspberry PI which was:

  • Served at a reasonable speed.
  • Easy to write.
  • Easy to maintain.
  • Portable to other platforms, should I choose to move to another server.

After looking high and low for a solution, I finally came across my answer: Pelican.

Full article here:
Pelican: A fast blog/CMS for the Raspberry Pi (874.org.uk)

Link: How to look up the geographic location of an IP address from the command line

If you want to find out where a given IP address is physically located on earth, there are quite a few online GeoIP lookup services you can try (e.g. geoiptool.com). These online services are mostly powered by freely available GeoIP databases such as those from MaxMind. Besides using such web-based services, there are different ways to query the GeoIP databases, notably via the Linux command line.

In this tutorial, I am going to describe how to geolocate an IP address from the command line in Linux.

Full article here:
How to look up the geographic location of an IP address from the command line (Xmodulo)
Related:
Geo IP Lookup API (ProgrammableWeb)

Link: How to Install Netflix on Linux

As omnipresent as Netflix is, it is not officially available on Linux yet. Thankfully, though, developers have come up with unofficial versions of the app. In this article, we’ll show you ways to get Netflix working — using these unofficial versions — on your Ubuntu or Fedora desktop.

Full article here:
How to Install Netflix on Linux (TechSource)

If for some reason you can’t get that to work, see our related previous article:
Link: Pipelight: Use Silverlight In Your Linux Browser To Watch Netflix, Maxdome Videos And More

Link: Tutorial: Customizing Your Bash Prompt

In this tutorial I will show you how you can change the look and behavior of the prompt to show more details or use a different coloring style. I will explain how to try all these examples and how to make changes permanently by adding them inside the Bash configuration file. Please note that this stuff is Bash-specific and it won’t work in other shells.

Full article here:
TuxArena | Tutorial: Customizing Your Bash Prompt (TuxArena)

RELATED: Some of you might prefer to run a program that customizes the bash prompt for you. For you there’s bash-prompt-customizer-cli at GitHub.