I got my copy of Mac OS X “Tiger” a couple days ago, and promptly fell upon the Widgets feature. I’m a web guy, and widgets (quite brilliantly) are essentially miniature web pages — they are constructed from all the same things you use to make web pages.
This, of course, makes them almost trivially easy to hack.
One feature of this Widget is that the entries have links in them, so that if you have the World Book Encyclopedia software installed on your computer, it takes you straight to the related article. That’s all well and good if you have that program, but I figured I could make it a bit more useful — so I rummaged around in the guts of the thing and jimmied it so that the links instead lead you to Wikipedia.
Here’s how to do it:
First off, I did this all in TextWrangler. (You can also use BBEdit if you have it.) If you don’t have TextWrangler, go download it — it’s free! (Truly, this is one of those programs that Apple should just stick on every Mac at the factory!) We’ll be using grep, but don’t worry if you’re not familiar with it, I’ll walk you through it all. (The reason I insist on the two programs listed above is that there are different variations of grep from application to application. BBEdit and TextWrangler, from the same company, have identical implementations.)
Okay, ready? Here we go….
- Go download the Widget and install it. To install manually, place it in the /Users/<you>/Library/Widgets/ directory.
- In Finder, right-click (control-click) on the Widget file and select “Show Package Contents”. This will open the widget file as a folder.
- From the “Day in History” contents folder you just opened, go into the “months” folder. You will see 12 documents, one for each month — “april.js” and so on. Select all of them and open them in TextWrangler.
- Under the Search menu (in TextWrangler) select “Find…”.
- Okay, here’s where it gets interesting. Make sure the “Use Grep” checkbox is checked. Also check the “Multi-File Search” box. A drawer will slide out of the side of the window. Check the “Open Text Documents” box. All 12 files listed under it should become checked when you do this.
- Run the following Find/Replace All:
- Replace All with:
- Next run the following Find/Replace All repeatedly until there are no more matches. (You should have to click “Replace All” six or so times. In TextWrangler you need to re-check the “Multi-File Search” box every time.):
widget\.openURL([^>]+)( ([^> ]+))>
- Replace All with:
- Third, Find/Replace All the following:
- Replace All with:
(Note: this step fixes any links that have a single-quote in the text. If there were any link text strings that had more than one single-quote, this would take two steps, one of which would be repeated like the previous one. Lucky for us, none have more than one single-quote.)
- Save and close all documents.
- Go into Dashboard and check it out. Either activate the widget as you normally would, or if it was already running, click on it and hit command-R to refresh it.
I’ve been playing with it and it runs like a champ. I think I’m going to have fun with widgets. Put questions in the Comments section. Have Fun! 🙂
and the Replace string for step 7 becomes:
Yep. That easy. 🙂
From comments I see that some people are having difficulties. I just ran through it again, doing straight “Cut and Paste”s from the strings presented in these instructions into the Find… Replace dialog in TextWrangler, so I know there aren’t any typos. Let’s see if we can figure some of this out….
First off, you can compare your results to mine This is line two of the file “may.js”, after the hack:
Hopefully that right off helps some people spot the problem.
Next are the following things to double check:
- Did you open all twelve month.js files? In TextWrangler, you should have had a Drawer slide out the side of the window showing all twelve open files.
- You open the Find…Replace dialog by clicking Find… in the Search menu. At the top of the dialog is the box for the Find string, and at the bottom is the box for the Replace string.
- Did you check the “Use Grep” checkbox in the dialog window?
- Did you check the “Multi-File Search” checkbox at the bottom of the dialog window? When you checked it and the drawer slid out of the side of the window, did you check the “Open Text Documents” box and confirm that all 12 files were listed and checked?
- Did you re-check the “Multi-File Search” checkbox each time you ran the second Find/Replace string?
- Did you avoid putting any extraneous spaces or linebreaks on the other Find or Replace strings?
- If nothing seems to have changed when you finished, did you refresh the view of the widget by hitting <command>-r?
If you’re still having trouble, drop me an email with line 2 from the file “may.js” pasted in, so I can get a good look at what’s going wrong.