Copy and Paste to OneNote (AutoHotKey script)

After yesterdays OneNote tool, I thought I’d do another while I think about it.

Another annoyance of OneNote is it’s lack of control over pasting information from the clipboard. I’ve raised a suggestion with MS to improve this; you can see my comment in the newsgroup.

To ease things a little if you need to copy and paste lots of stuff to OneNote, here is an AutoHotKey script to help. You need to assign this to a hot-key and have OneNote open in the background. Select something and press the hot-key and it will be pasted (using the current default paste option as this cannot be controlled) into the current note in OneNote.

; AutoHotKey Script to copy pre-selected stuff from the currently active window
; to the currently open note in OneNote
;
; Usage: #include in your main AutoHotKey.ahk assigned to a hot key
; Limitations: 
;       1) OneNote must be open - maybe change this in the future so that content goes to a new unfiled note
;       2) Doesn't swap back to original application
;
; Author: Julian Knight, http://www.knightnet.org.uk/contact.htm
; Version: 2009-04-01 v1.0

; We need a partial title match but we will also reset to previous setting
oldTitleMatchMode := A_TitleMatchMode
SetTitleMatchMode, 2

; Settings
winTitlePart := " - Microsoft Office OneNote"   ; Partial title of ON windows

; Copy currently selected stuff
SendPlay, ^c                    ; Use sendplay to avoid unexpected interactions with Win key

; If OneNote is not started, give up
IfWinExist, %winTitlePart%
{
        ; Save the currently active window title
        WinGetTitle, actWin, A
        
        ; If OneNote is not active, activate it now
        IfWinNotActive, %winTitlePart%
                WinActivate, %winTitlePart%

        ; Check again, if ON active then paste else error
        IfWinActive, %winTitlePart%     
        {
                ; Paste to ON & Add some blank lines
                SendPlay, ^v`r                  ; Use sendplay to avoid unexpected interactions with Win key
                ; Switch window back to previously active
                WinActivate, %actWin%
        }
        else
                MsgBox, Could not activate OneNote window.
                
} else
        MsgBox, Can't find ON [%winTitlePart%]

SetTitleMatchMode, %oldTitleMatchMode%
return


Technorati : , , , , , ,
Diigo Tag Search : , , , , , ,

Setting list item gaps in Microsoft OneNote (AutoHotKey script)

Although I like Microsoft OneNote and use it continuously, it does have a few failings. One of these is the inability to set the default styles and layout for text.

In particular, when you create a new paragraph or list entry in OneNote, the default – non-changeable – setting is to have no white space between the paragraphs.

This is very poor design and makes more than a small amount of text quite unreadable. I’ve raised this with Microsoft but who knows if or when it might be sorted.

In the mean time, I need a far quicker way of changing this. Currently, I’ve had to:

  1. Select the container with the text I want to format
  2. Use the menu to show the List Task Pane ([alt]o/L)
  3. Mouse click on the text box to change (you cannot tab into it)
  4. Change the 0.00 pt default to something like the 6.00 pt that I prefer
  5. Close the List Task Pane

Not nice!

Having determined that there is nothing clever that can be done in OneNote, I decided that the old standy “AutoHotKey” would be useful. So I’ve created a script for AutoHotKey that will change the inter-list gap for the currently selected container.

; [win]-z Set OneNote list to 6pt separation
#z::
; We need a partial title match but we will also reset to previous setting
oldTitleMatchMode := A_TitleMatchMode
SetTitleMatchMode, 2

debug            := 1                                                           ; Set to 1 to output debug messages, or 0
winTitlePart := " - Microsoft Office OneNote"   ; Partial title of ON windows
winText          := "List"                                                      ; Text to identify List Task Pane - Visible Window Text: MsoDockRight, Task Pane, List
listDefault      := "0.00 pt"                                           ; The default setting for list separation between items
listNew          := "6.00 pt"                                           ; My desired spacing between list items

; Only do something if ON is the active window
IfWinActive, %winTitlePart%
{
        ; We need the List Task Pane to be visible
        IfWinNotExist, %winTitlePart%, %winText%
        {
                ;IfEqual, debug, 1, MsgBox List not active
                ; Send chars to activate menu, can't use WinMenuSelectItem with Office apps
                ;   SendPlay is used to prevent the Windows key locking the PC (Win+L)
                SendPlay, !oL
        }
        ; List Task Pane should now be visible, save the existing setting
        ControlGetText, Var1 , RichEdit20W2, %winTitlePart%, %winText%
        ; If the current setting is the default setting then make the change
        if Var1 = %listDefault%
        {
                ; Focus on the input box & set the text
                ControlFocus, RichEdit20W2, %winTitlePart%, %winText%
                ControlSetText, RichEdit20W2, %listNew%, %winTitlePart%, %winText%
                ; This is optional to check if we were successful
                ControlGetText, Var2 , RichEdit20W2, %winTitlePart%, %winText%
                if ErrorLevel   ; i.e. it's not blank or zero then error
                        MsgBox, %Var1% - %Var2% - Problem - %ErrorLevel%.
                else
                        IfEqual, debug, 1, MsgBox, OK - %Var1% - %Var2%.
        }
        ; Close the List Task Pane (actually it closes the Task Pane, period, sorry)
        SendPlay, ^{F1}
}
else    ; ON not active so do nothing
        IfEqual, debug, 1, MsgBox, OneNote not active

SetTitleMatchMode, %oldTitleMatchMode%
return

OK, so it’s a bit rough-and-ready but it does save a whole lot of time. I’ve got this in my default AHK script so it is loaded whenever I log in and is activated with [win]z.


Technorati : , , , , , ,
Diigo Tag Search : , , , , , ,