powershell

Open Live Writer + Syntax Highlighting

I have been trying to get the open source fork of Windows Live Writer to recognize plugins for ages now, have tried

Nothing seemed to work. Then I was just about to give up, then I came across this post : https://blogs.technet.microsoft.com/simonbrown/2017/06/23/using-open-live-writer/ by Simon Brown that just rained unicorns on my rather gloomy day

Simon has written this PowerShell script that you run once, and then just Restart Open Live Writer, and bingo by plugin now works.

Here is his script, thanks Simon you rock

#download zip file for syntax highlighting
$url = "https://richhewlett.blob.core.windows.net/blogdownloads/SyntaxHighlight_WordPressCom_OLWPlugIn_V2.0.0.zip" 
$path = (Get-Item -Path ".\" -Verbose).FullName + "\SyntaxHighlight_WordPressCom_OLWPlugIn_V2.0.0.zip"

Write-Host "Downloading [$url]`nSaving at [$path]" 
$client = new-object System.Net.WebClient 
$client.DownloadFile($url, $path ) 
      
#create destination directory
$LocalAppDir = [Environment]::GetFolderPath("LocalApplicationData")
$OpenliveWriterDir = $LocalAppDir + "\OpenLiveWriter"

#just in case there are multiple versions installed, or there's an upgrade, enumerate the application binary folders
$appDirectories = Get-ChildItem $OpenliveWriterDir | Where-Object {$_ -like "app-*"};

foreach ($appDirectory in $appDirectories) {

    #Create destination directory
    $targetDir = $appDirectory.FullName + "\Plugins"
    if(!(Test-Path -Path $targetDir )){
        Write-Host "Creating path $targetDir"
        New-Item -ItemType directory -Path $targetDir
    }


    #decompress file into target directory
    Write-Host "Expanding $path to $targetDir"
    Expand-Archive $path -DestinationPath $targetDir

    #update config file
    $configFileName = $appDirectory.FullName + "\OpenLiveWriter.exe.config"
    [xml] $xml = gc $configFileName

    #create the new element
    $newitem = $xml.CreateElement("loadFromRemoteSources")
    $newitem.SetAttribute("enabled","true")

    #if it doesn't already exist in the file, add it and save
    if (!$xml.SelectSingleNode("//loadFromRemoteSources")) {
        $xml.DocumentElement.LastChild.AppendChild($newitem)
        $xml.Save($configFileName)
    }    
}

Woohoo

2 thoughts on “Open Live Writer + Syntax Highlighting

  1. Hi Sacha, I am using the windows store version of open live writer and it does not seem to work with that version. Any ideas?

Leave a comment