I'm sure it comes as no surprise to you that I do a fair bit of blogging and writing. This means I am always on the look out for tools and tricks to make the process easier. Recently Scott Hanselmen and others announced a resurrection of the old Microsoft Live Writer tool into an open source project. You can learn more about Open Live Writer here.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
I decided to give it a try and while obviously there's a lot of updating to do, one feature I like is the automatic linking. When I type something, like Get-Eventlog the program will automatically insert a link. You can manually set these links up in the program. But because I write a lot about PowerShell cmdlets, which have online links, I didn't want to manually have to create hundreds of links.
So with some pointers from other community members I learned that the autolink information is stored as a simple XML file under $env:APPDATA\OpenLiveWriter\LinkGlossary\linkglossary.xml. The file layout is pretty simple.
This means I can use PowerShell to create new entries.
First, I get the existing XML content.
$Path = "$env:APPDATA\OpenLiveWriter\LinkGlossary\linkglossary.xml" [xml]$xml = Get-Content -Path $Path
Then I create new Entry element.
$entry = $xml.CreateNode("element","entry","")
The node has properties for text, url, title, rel and openInNewWindow, all of which are case sensitive which is important to remember when working with XML. I'll need to create an entry for each property. The process is the same for all the items.
$textentry = $xml.CreateElement("text")
Now I have a new XML object.
The text that I want to auto link to is going to be PowerShell.org.
$text = "PowerShell.org" $textentry.InnerText = $Text.Trim()
I like using Trim() on strings, to eliminate any extra spaces. Once this is complete all I need to do is append the text entry to the entry node.
$entry.AppendChild($textentry)
I repeat the process for the URL
$url = http://PowerShell.org $urlentry = $xml.CreateElement("url") $urlentry.InnerText = $url.trim() $entry.AppendChild($urlEntry)
The Title:
$title = "Learn more about PowerShell.org" $titleEntry = $xml.CreateElement("title") $titleEntry.InnerText = $Title $entry.AppendChild($titleEntry)
The Rel link I'm not using so I'll create an empy setting.
$relEntry = $xml.CreateElement("rel") $relentry.InnerText = "" $entry.AppendChild($relEntry)
And finally whether the link should open in a new window.
$open = $xml.CreateElement("openInNewWindow") $open.InnerText = "True" $entry.AppendChild($open)
Note that this needs to be a string and not a PowerShell boolean value. I now have a complete autolink entry.
All I need to do is append it to the XML document and save the file.
$xml.glossary.AppendChild($entry) $xml.Save($Path)
Naturally I needed a function to do all of this which I have posted as a Gist on GitHub.
With this function, I also added code to update an existing entry. But now I can use PowerShell to find all commands that have a help link and add them to the autolink XML file.
get-command -CommandType cmdlet | where HelpURI | select name,HelpURI | Update-OLWLinkGlossary -Title "Read online help for this command"
I recommend updating the file when Open Live Writer is not in use. When you update the file, you should see all of your new entries.
You may not be a blogger or author, but hopefully my script will give you some pointers on working with XML files.
Ok…you’ve given me a really good reason to start using open livewriter.
Thanks for sharing!
There are plenty of areas for improvement as you would expect, but the community that has sprung up around this project is pretty intense.