I'm certainly not a PowerShell expert but I have been finding my way around it lately. Once I got a few interesting scripts put together and saved to a file the next thing I ran up against was how do I launch these without loading them into the interactive environment by hand? By default when you install PowerShell it associates script files (.ps1 files) with notepad. Great for editing, not so great if you want to execute them. My guess is that after the 'Monad/PowerShell virus' story a year back or so that Microsoft got a little too freaked out to just let these things launch when clicked on. Unfortunately this decision also makes it more difficult to schedule a PowerShell script in the task scheduler too. To top it all off it's not quite as simple as just passing your script as a command line argument to PowerShell either. There are two separate steps necessary to enable you to launch PowerShell scripts from the Windows shell.

First you have to set up a file association in the Windows shell to change the default behavior for .ps1 files. However the PowerShell command line doesn't know what to do with a script file. By default it simple takes statements to execute. We can leverage this to our advantage though and construct a statement to cause our script file to be loaded and executed. That statement looks something like this:

powershell -command "& 'MyScript.psa1' "

If you update the file association with this you can then launch script files from the command line or by clicking on them. You can use the Tools | Folder Options dialog to do this but why not use PowerShell instead? Here are two simple lines of code to update your system registry to tell it how to execute .ps1 script files.

Note: This of course updates your system registry so you should back things up first.

new-item Registry::hkey_classes_root\microsoft.powershellscript.1\shell

new-item Registry::hkey_classes_root\microsoft.powershellscript.1\shell\open

new-item Registry::hkey_classes_root\microsoft.powershellscript.1\shell\open
\command -value ('"' + $PSHOME + '\powershell.exe" -command "& ''%1''"')

If you run these two PowerShell lines and then try and click on a .ps1 script file you'll see that we're not quite there yet. PowerShell has an execution policy that by default is set to "Restricted." In restricted mode no scripts are allowed to execute, only interactive commands may be executed. By using the PowerShell "set-executionpolicy" cmdlet you can change it to something more sensible like RemoteSigned which allows all locally generated scripts to execute but will only allow downloaded scripts to execute if they have been signed by a trusted source. In PowerShell you can execute the "help  about_signing" command for more info on this.

Once these two steps are done you can now launch PowerShell scripts directly without having to start up the interactive environment first. In addition you can also use this method to schedule PowerShell scripts in the task scheduler.


Many larger applications having scripting capabilities built in to allow you to automate repetitive tasks but what do you do if you need to script a repetitive task for an application that doesn't have a scripting or macro language built in?  You could use VBScript and the SendKeys function. This works for simple things but it isn't always robust enough. What if you need to do something more complex, for instance: launch an application, wait for the main window to open, resize the window, send some keystrokes, and then click on a specific UI element? Unfortunately VBScript and its set of built-in functions don't always cut it when you need to move beyond SendKeys.

When your needs go beyond what VBScript can do natively you might want to take a look at AutoIt. AutoIt is a small suite of tools, the main component being a stand-alone scripting language. What sets AutoIt apart from other scripting languages is that it is targeted at GUI application scripting and its built-in set of functions enable the finer level of control lacking in VBScript and other scripting languages. The AutoIt scripting language is very VB-like and easy to pick up if you're already familiar with VB. AutoIt has a rich feature set including (taken from the AutoIt web site):

  • Provide a general-purpose scripting language for all Windows versions
  • Simulate keystrokes (supports most keyboard layouts)
  • Simulate mouse movements and clicks
  • Move, resize and manipulate windows
  • Interact directly with "controls" on a window (set/get text from edit controls, check boxes and radio buttons, select items in drop-down lists, etc.)
  • Create complex user interfaces (GUI's)
  • Work with the clipboard to cut/paste text items
  • Provide a scriptable RunAs function for Windows 2000/XP/2003

However what is really interesting to me is that AutoIt also includes a scriptable COM object essentially making its core application scripting capabilities available to any other COM capable languages including VBA, VBScript, PowerShell, or .Net. The COM interface on this object seems well thought out and is very easy to use. I started using AutoIt for this feature as I needed to automate an application from within Outlook's VBA scripting. Using the AutoIt COM object I was able to write Outlook VBA code to control another application including starting the application, waiting for its main window to launch, and intelligently sending data to the right parts of its UI.

And best of all, AutoIt is free. It can be found here.

Note: PowerShell is on the horizon and by all accounts it should be a very powerful tool but it also seems to lack some of this finer level of control for scripting GUI applications. You can however access the AutoIt COM object as well as the full .Net library.


First, a little context on why I wanted to do this in the first place. If you just want to get the source code then just scroll down to the "The source code".

A fair number of the things that make it on to my ToDo list are messages that I receive in Outlook. I've been using Outlook's flags to mark these items for follow up so that I could keep track of them. I use a different colored flag that denotes its own meaning as defined by me. This way I can flag an item using a action type (ToDo, Deferred, Waiting For, etc...). This has worked fairly well for me but once I had a large number of items flagged in Outlook (did I mention that I am a procrastinator?) it didn't really help me keep track of the things I needed to keep track of in any meaningful way. All I could even see was the complete list of flagged items but I couldn't break it down further into projects or context.

To overcome this limitation I've recently started managing my ToDo list outside of Outlook in a program called MyLifeOrganized (aka MLO) . MLO allows you to drag/drop Outlook items into MLO's task list. When you do this it creates a new MLO task using the subject of the dropped Outlook item for the task name. However MLO does something else really smart when you drag/drop an Outlook item. It not only put the text of the Outlook item into the notes, it will also create a hyperlink that will open up the original Outlook item when clicked. It does this by using Outlook's URL syntax which looks something like this:

Outlook:<entry_id> where <entry_id> is an Outlook Entry ID

Windows naturally understands this form of URLs. If you click on one it will cause Outlook to open the item referenced. This has allowed me to take Outlook items and create MLO items simply by dragging them to the MLO task list. In most cases this feature in MLO does exactly what I want, take an Outlook message that I need to follow up on and place it into my ToDo list. However sometimes this isn't exactly what I want. Sometimes I just want to place a link to Outlook items in the notes of an existing MLO item. Unfortunately MLO doesn't support this but there is a way to do it if you willing to do a little macro work in Outlook.

Update 6/4/2007: If you are using Office 2007 then you will probably need to enable the Outlook URL protocol handler so that hyperlinks to mail messages work.To do this requires editing the registry. You simple need to create these registry keys (substituting your installation paths of course):

  • HKEY_CLASSES_ROOT
    • outlook
      (Default) = URL:Outlook Folders
      URL Protocol=""
      • DefaultIcon
        (Default) = "C:\PROGRA~1\MICROS~2\OFFICE12\OUTLLIB.DLL,-9403"
      • shell
        • open
          • command
            (Default) = "C:\PROGRA~1\MICROS~2\OFFICE12\OUTLOOK.EXE" /select "%1"

The source code

Below is the source for a two VB macros that can be added to Outlook. These macros will loop over all of the currently selected messages, getting the subject and Outlook EntryID for each message. With these two pieces of information they then build a string of text with the message's subject and its Outlook URL, each on their own line. It extends this text string for each selected message and places the resulting text string on the clipboard. The end result is one block of text that contains the message subject followed by the Outlook URL for each selected message. This text can then be pasted into any document that understands hyperlinks. This includes the notes of MLO items as well as all of the other Microsoft Office applications. This macro will work with multiple items selected in the main Outlook window as well as from the opened window of a single Outlook message. To use it, simple invoke the CopyItemIDs() macro. You can bind this macro to a menu or toolbar button for easier access within Outlook.

Note: I should mention that if you are using Microsoft Exchange server, the message Entry ID can change on you and break any existing Outlook URLs. This unfortunately always happens if you move a message to another folder so if you plan on using this, only invoke this macro after you have moved the message to a new folder.

Update: There is just one more thing you must do before you run this script. You need to include a reference to FM20.dll, which is the Forms 2.0 library. This will allow you to use the DataObject to manipulate the clipboard. Thanks to 'Some Guy' who pointed this omission out.

Sub CopyItemIDs()
    Dim myOLApp As Application
    Dim myNameSpace As NameSpace
    Dim currentMessage As MailItem
    Dim ClipBoard As String
    Dim DataO As DataObject
    
    ' Housekeeping: set up the macro environment
    Set myOLApp = CreateObject("Outlook.Application")
    Set myNameSpace = myOLApp.GetNamespace("MAPI")
    
    ' Figure out if the active window is a list of messages or one message
    ' in its own window
    On Error GoTo QuitIfError    ' But if there's a problem, skip it
    Select Case myOLApp.ActiveWindow.Class
        ' The active window is a list of messages (folder); this means there
        ' might be several selected messages
        Case olExplorer
            ' build the clipboard string
            For Each currentMessage In myOLApp.ActiveExplorer.Selection
                ClipBoard = GetMsgDetails(currentMessage, ClipBoard)
            Next
             
        ' The active window is a message window, meaning there will only
        ' be one selected message (the one in this window)
        Case olInspector
            ' build the clipboard string
            ClipBoard = GetMsgDetails(myOLApp.ActiveInspector.CurrentItem, _
                                         ClipBoard)
        ' can't handle any other kind of window; anything else will be ignored
    End Select
    
QuitIfError:       ' Come here if there was some kind of problem
    Set myOLApp = Nothing
    Set myNameSpace = Nothing
    Set currentMessage = Nothing

    Set DataO = New DataObject
    DataO.Clear
    DataO.SetText ClipBoard
    DataO.PutInClipboard
    
    Set DataO = Nothing

End Sub

Function GetMsgDetails(Item As MailItem, Details As String) As String

    If Details <> "" Then
        Details = Details + vbCrLf
    End If
    Details = Details + Item.Subject + vbCrLf
    Details = Details + "Outlook:" + Item.EntryID + vbCrLf

    GetMsgDetails = Details

End Function

Here’s a tip for tracking important email responses that you’re waiting for. Many email clients these days support flagging or labeling items as well as rules for processing items. I use Outlook as my email manager which has a robust set of rules and in the 2003 version, something called “search folders” which are saved searched that you can quickly access. Using Outlook I can set up folders to automatically sort all of my emails with a certain flag into one place for quick access. In my email system I use flags for managing the flow of “Next Actions” as defined in GTD (Getting Things Done by David Allen). Right now I have a fairly simple set of flags that I use, “Action”, “Deferred”, and “Waiting For”. Anything else that is not flagged is by default considered reference information (or completed actions if I have checked them off).

The “Action” and “Deferred” flags are pretty self-explanatory; it means that there is an action (or possible future action) that I need to perform; usually something that takes more time than a quick response. “Waiting For” is also fairly self-explanatory but its use is sometimes a little more complicated in practice.

In most cases I use it to simple flag something that I am waiting for, such as flagging an order shipment email or flagging something important that someone has told me they would follow up on. Where it gets more complicated is when I need to track a request that I am sending to someone. In those cases I use a special rule to flag a copy of the item as “Waiting For”. In Outlook I have a rule set up that checks for emails that I have Cc’s to myself. When Outlook’s rule engine finds those items it marks them as read and flags them as “Waiting For”. Now whenever I want to track a request to someone, I just Cc myself on the request and a reminder will automatically be generated and filled in my “Waiting For” folder.


I’ve recently discovered a name (and a tool) for something that most of us do but that I didn’t know had a name. It’s called Mind Mapping and if you’ve written on a whiteboard chances are you’ve already done it. Mind Mapping in its simplest form is just writing down your thoughts in a visual way, i.e. text connected with lines and more text. The real discovery for me however was not that it had a name but rather that there are tools out that facilitate creating mind maps on a computer. The product I found is called MindManager from MindJet and from what I can tell they seem to be the market leader and for good reason. They have a well designed and functional product equally on par with anything in Microsoft Office, which it can fully integrate with.

While MindManager can be used with any PC the real beauty of this program is that it is probably the best TabletPC program out there, far better than anything Microsoft has ever produced. When installed on a TabletPC it has a special Pen mode that takes full advantage of all the features of a TabletPC including gestures. Creating mind maps this way is very fast and intuitive. You can insert text, drawings, make connections, etc… all with simple strokes of the TabletPC’s pen.

So what does a MindManger mind map look like? Here’s a simple example (you can click on it for a larger view)


 

 

This is a very simple example of a mind map (there are many more in the MindJet.com online gallery) and in fact they can look just about anyway you like. There is an abundance of styles and images included that you can use to build mind maps. You can also link in live data from other sources (excel, outlook, databases, etc…). In addition to capturing text you can also insert hyperlinks to other maps or external sources.

Besides just capturing thoughts and ideas you can use mind maps for all sorts of things like taking notes during a meeting or creating process flow diagrams or even creating dashboard type diagrams that link to other sources of information.

After reading about it I was eager to try it but I waited until I had a good idea that I wanted to capture. I’ve always been unsatisfied with handwritten notes, both on paper and electronic especially when trying to capture complex thoughts. Usually I find that when I go back to them (if I can read them) I have a hard time recalling the thinking behind the notes. My notes just don’t seem as connected to my original thoughts or my original thought process. Some when my next big idea came along, I picked up Mind Manager and starting creating a mind map of it. I was amazed at how quickly I could capture thoughts and more importantly, relate them to one another. Rearranging my thoughts throughout the capture process was also easily done just by dragging things around. I found it far more effective at capturing and organizing my thoughts than paper. Running out of room for inserting new thoughts was just not an issue at all.

The real test though came days later after I had captured my original thought stream and went back to try and decipher it. I found that my mind map notes made more sense to me than the chicken scratch I normally write down. I could see the connections between my thoughts much better than with my old note taking style. The best thing however was how easy it was to extend the map with new thoughts. As I drilled down deeper into my original notes adding new layers was by far easier than any other system of note taking I have ever used. It made me an instant convert. I would highly recommend giving it a try.

MindManager is available for both the PC and Mac. You can download a free 21-day trial from MindJet.com. Be warned though that it is not cheap, retailing at $350 for the Pro version (I got my copy for $275 on Ebay though).


Flux and Mutability

The mutable notebook of David Jade