when you want your computer to do something...

Jan 25, 2006 04:13

...there's usually a way to make it do what you want.

I recently got a "mailto:" link (which was probably created automatically by AIM) in an IM from a friend because fskornia wanted me to send him a test message. Well I use gmail with firefox. While there's an extension to open "mailto:" links from inside firefox, there isn't one to get firefox to deal with these links from external programs. So, I decided to play around and make it so if I click said link, even from AIM, firefox will open it in a compose page for gmail. About 2 or 3 hours later, it's working like a charm and I'm happy.

Among the various acknowledged points of wisdom does happen to be "Of all the external mailto links you're going to come across, surely you will spend less than 2-3 hours combined if you were to just copy and paste the address." Well, yeah, that's true. Of course what I ended up writing has full support for mailto links though (like subjects, cc addresses, and such) which would be annoying to copy and paste out. Then again, I'm only worried about external mailto links and those just don't happen that often. Whatever, I feel happy and accomplished. Especially since I only used shell scripting (and it's really not that powerful in windows).

For those interested, this is what I came up with:

contents of "c:\windows\mailto.bat"...
@echo off
echo %1|sed -f "c:\windows\mailto.sed" > "C:\windows\mailto.url"
set /P url=<"c:\windows\mailto.url"
del "c:\windows\mailto.url"
Start "C:\Program Files\Mozilla Firefox\firefox.exe" %url%

contents of "c:\windows\mailto.sed"...
#get rid of beginning and ending quotes
s/^"//
s/"$//

#get rid of "mailto:" at beginning
s/^[Mm][Aa][Ii][Ll][Tt][Oo]://

#do a bit of url escaping
s/@/%40/g
s/ /%20/g
s/~/%7E/g
s/\^/%5E/g
s/#/%23/g

#Do mailto->gmail substitutions in the url
#change ? -> &
#change subject= -> su=
s/?/\&/g
s/[Ss][Uu][Bb][Jj][Ee][Cc][Tt]=/su=/

#add the gmail address to the beginning
s/^/http:\/\/mail.google.com\/mail?view=cm\&fs=1\&to=/

#put quotes back around it
s/^/"/
s/$/"/

Then I changed the registry key \\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\mailto\shell\open\command to "c:\windows\mailto.bat" "%1"

That's about it. Obviously requires sed to be on your system, but that's not hard to track down if you don't have it.

I'm sure part of why I did this is simply because it's my hobby. That and for some reason I really have no problem spending a few hours on something now if it makes things cooler/smoother/more streamlined/easier later. In other words, I'm lazy but willing to work toward future laziness.

Feel free to use the code at will if you want it. Although for some reason I think I'm the only one with an apparent "need"...

email, gmail, shell scripts, laziness, internet, firefox, coding

Previous post Next post
Up