Archive for June, 2007

Wish: AutoComplete add-in for Word that suggests words from current document

June 20, 2007

UltraEdit has a nice feature in which when you press Ctrl-Space, an auto-complete list is opened, suggesting you to complete the word you just started to type. The nice thing is that its suggestions come not only from the list of keywords of the edited file’s language, but also from the actual words in the file (actually, the words above you current location).

This is great as you often use the same words several times in a file, and it can be handy for your editing tool to use that and suggest options from your current work, which probably knows the words in the domain more then any general keywords dictionary file.

I really wish someone would have written an add-in to Microsoft Word that does it. I might get to it some time when I have time (as if… ha).

Javascript: Function.prototype.toString returns an optimized version of the function

June 17, 2007

I was working an a user script for Gmail (I’ll link to it when it’s done), and could not understand why some code didn’t run on a specific page.

One of my tricks of seeing a Javascript function body when the function is dynamically added is to call the function toString() (e.g. in Firebug console). Regretfully, Firebug doesn’t tab-complete functions’ methods, so I have to manually type “toString()”. (I opened issue 959 for this.)

However, in the code I wrote, I accidentally wrote something like:

var count = getCount();
if(count == 0)
    count == 1;

Note the bug in the last line, where the comparison operator (==) is used instead of the assignment operator (=). Surely, my mistake. However, when I look at the text that was returned from the call to Function.prototype.toString() for that function, I saw it is:

var count = getCount();
if (count == 0) {

So the Javascript engine noticed that nothing really useful is going on in the body of that if, and simply removed it, and that is reflected in what Function.prototype.toString returns. I didn’t knew that.


Naturally tools like JSLint warn about this problem:

Expected an assignment or function call and instead saw an expression.

count == 1;

But this is a minor user script, and I never considered passing such scripts through JSLint. I might consider starting doing it for my scripts…

A solution to quickly moving mail items from Outlook inbox

June 12, 2007

My usual way of handling e-mails is reading them in the inbox which collects both work-related e-mails from the Exchange server and private e-mails from my Gmail inbox using SMTP and POP3., and then dragging them to the the appropriate folder in one of the PST I have.

I know that since I index my mails and it is lightning fast to find any e-mail filing each e-mail in a specific related folder is less important, but kind of used to it, and I still find it useful to be able to go to a folder and see all the mails that I decided that belong to that folder, and not all the files that match some search. This has prove itself useful mainly in customer related data, where searching the customer name would have bring way too many mails, but looking at the customer folder quickly revealed the old case I was looking for. By the way, these is one of the reason I prefer Outlook to Gmail. Outlook can easily help me categorize my mails in hundreds of hierarchical folders, where Gmail provides a flat list of labels, which might not be useful for more than a few dozens.

My problem was that whenever I wanted to move a mail to a folder, I would have to find the folder in the folders tree, in order to drag the mail into it. This might be annoying for commonly used  folders like the folder that keeps mails from CodeProject (I’m subscribed to it although I rarely develop in Microsoft technologies. I enjoy skimming through it looking at what’s new in that area. Occasionally I even find an interesting article).

When a mail is opened in Outlook editor, which has the new ribbon, the ribbon has a clever Move to Folder item which opens a list of recently used folders. However, if I don’t want to open the mail, and only want to move it to a folder from the index, I have to find the folder in the tree and drag it to it.

One solution is to use the Favorite Folders to put shortcut to commonly used folders in a fixed place, and then drag mails to that folder shortcut, and not to its location in the tree. This has two drawbacks:

  1. The list tends to grow all the time, and I end up with a big list of “Favorite Folders” which I rarely ever navigate to – I only use them as drag targets.
  2. Sometimes Outlook crashes and the list of Favorites folder is reset, and I have to start building it from scratch.

Today I came up with a new solution – use macros.

I wrote the following VBA procedure:

Private Sub MoveItemsToFolder(folderID As String)
    Dim item As MailItem
    Dim targetFolder As Folder
    ' Folder ID can be obtained by selecting the folder
    ' in Outlook and then typing in the immediate window:
    '   ?ActiveExplorer.CurrentFolder.EntryID
    Set targetFolder = GetNamespace("MAPI").GetFolderFromID(folderID)
    If ActiveExplorer.CurrentFolder = targetFolder Then
        MsgBox "You are already in '" & targetFolder.Name & "'.", vbCritical
        Exit Sub
    End If

    For Each item In ActiveExplorer.Selection
        item.Move targetFolder
    Next item
End Sub

and then I wrote small procedures like the following:

Sub MoveToPrivate()
    MoveItemsToFolder "0000000045DC3C0FFF1EA54CBAD9147BB26AF269A2800000"
End Sub

Sub MoveToCodeProject()
    MoveItemsToFolder "00000000A7E4D138E838B7489BA3F839949B055122860000"
End Sub

Then I created a new menu in Outlook toolbar, and added these procedures as items to this toolbar menu. So now, when I want to move a mail to a folder, I simply select it and click the appropriate button.

As the comment says, if a new folder is needed, I select it and open the VBA editor, and type


in the immediate window. I didn’t have an Outlook crash yet, so I don’t yet know if crashes that reset the favorite folders also reset toolbar customization, but at least the first problem is solved – my favorite folders only contains folder I navigate to regularly, and not all the folder I periodically get mails that should be filed under them.

Macro keyboard shortcuts in Excel 2007

June 10, 2007

I’ve just written a new macro in Excel, and wanted to assign Ctrl-Shift-F to it, as it does some advanced finding. However, the Shortcut key field that appears in the Record Macro dialog and also in the Options… dialog opened from the Macros dialog, it seems to only be possible to assign Ctrl-<something> to a macro, and not Ctrl-Shift-<something>.

Disappointed, I choose Ctrl-E instead. Cursing Microsoft again for not putting a decent keyboard customization feature in Excel 2007 (and also in Outlook Editor), like they did in Word 2007.

But then I recalled that I already had a macro that copied the content of the selected cell, and I’m used to activate it using Ctrl-Shift-C. I want back to the Options… dialog and found out that although it says Ctrl+<something>, if you type Shift-<something> in that field, the Ctrl label changes to Ctrl+Shift.

I’d say that’s not the most discoverable feature I’ve seen…


The Macro I use for copying a cell (or cells) content is as follows:

Sub CopyCellContent()
    Dim MyData As DataObject
    Dim s As String
    Dim i As Long
    Set MyData = New DataObject
    If IsArray(Selection.Value) Then
        s = Selection.Cells(1).Value
        For i = 2 To Selection.Cells.Count
            s = s & ", " & Selection.Cells(i).Value
        Next i
        MyData.SetText s
        MyData.SetText Selection.Value
    End If
End Sub on Firefox

June 6, 2007 is a an Israeli video sharing site, and recently I noticed that when someone links to a movie over there, my Firefox fails to display it, and I have to revert to IE to display. That doesn’t happen that much for me to install the IETab extension. but today, I decided to check what’s going on, and see if a user script can be written to overcome it.

One of the strangest things was that I saw no complaint about it in the Israeli Blogosphere, and I thought that if there was a problem with Firefox support on that site, bloggers would have rant about it, and someone would even write a user script to solve it.

However, when I checked it I found out that the site uses Javascript libraries from when the “send movie to a friend” feature is used, in order to import their address book. Normally, this should not be a problem, but SmartFilter defines as “Social Networking” and such sites are blocked by our IT people as non-job related site, so when the browser requests it, it gets an error HTML, and if it tries to treat the returned page as JavaScript code, errors occurs. For some reason I didn’t quite understand, IE can cope with that JavaScript error, but Firefox stop execution the code in the page, so the movie Flash <object> and <embed> tags are not created, and the movie is not displayed.

After that was found, it was easy to write a user script that creates that movie Flash <embed> tag if the page failed to do it.

Checking it some more, I saw that if you refresh the page several times the movie start playing. This might be related to the fact that the libraries are loaded in an <iframe>, and the load order might change.

June 4, 2007

After I read some more people saying how Launchy is really good, I thought I’d give it a try, although I said I’m not the kind of guy who uses it.

In fact I found it useful for some types of task. I really enjoyed finding out that it is learning, so if you once type one or two letters and select an app from the list and not take Launchy suggestion, Launchy will remember your selection, and the next time you type these letter(s), you will get your last selection as the first suggestion. This made me teach Launchy to start some applications using their first letter such as O for Outlook and F for firefox. This is mainly useful in my laptop startup process at home, where I start Firefox and Outlook after connecting to VPN. I know I could have written a script to do it, but Launchy makes it very easy to do it without writing that script.

Another usage I found useful is to mute or "unmute" the speaker. Before Launchy, if I didn’t know if the speakers were off or not, and I wanted to turn them on or off, I had to click the speaker icon in the system tray, wait two seconds for the volume slider to appear, and then set the Mute checkbox to what I want. After I started using Launchy, I downloaded mute.exe from here, and then created two shortcuts – mute.lnk and unmute.lnk, and then I "taught" Launchy to use "M" and "U" to run them.

I did find some problems with it:

  • It doesn’t support Hebrew. I tried running a Firefox favorite with a Hebrew name, and it just didn’t find it. Maybe it’s just the Foxy plugin that sucks, since it does find Hebrew strings in the Start menu.
  • Trying to teach him to run a Firefox favorite with just one letter behave strangely. It keeps showing the favorite page title, instead of the name of the favorite.
  • It would be nice if whenever it saw the beginning of a file path (like "C:’" or "’’host’") it would auto-complete it, but do it properly, like Total Commander 7 does it.