Skip to content

Instantly share code, notes, and snippets.

@mhart
Last active October 13, 2019 02:18
Show Gist options
  • Save mhart/96dad3689cccc04a088522249d27c03e to your computer and use it in GitHub Desktop.
Save mhart/96dad3689cccc04a088522249d27c03e to your computer and use it in GitHub Desktop.
Quick hack to convert from NetNewsWire 3.x to something you can import into 5.x
// First, create a new directory, copy this file into it, and run: `npm install xml2js`
// Then `plutil -convert xml1 ~/Library/Application\ Support/NetNewsWire/Subscriptions.plist`
// Then `node plistToOpml.js > exported.opml`
// Then File->Import Subscriptions... in NetNewsWire 5.x
const fs = require('fs')
const xml2js = require('xml2js')
const data = fs.readFileSync(`${process.env.HOME}/Library/Application Support/NetNewsWire/Subscriptions.plist`, 'utf8')
const parser = new xml2js.Parser({ explicitChildren: true, preserveChildrenOrder: true })
;(async() => {
const result = await parser.parseStringPromise(data)
const items = result.plist.array[0].dict.map(item => item.$$)
console.log('<opml version="1.0"><body>' + toObjArray(items).map(toXml).join('\n') + '</body><opml>')
})()
function toObjArray(items) {
return items.map(item => {
if (item.length % 2 !== 0) throw new Error(JSON.stringify(item))
let itemObj = {}
for (let i = 0; i < item.length; i += 2) {
if (item[i]['#name'] !== 'key' || !item[i]._) throw new Error(JSON.stringify(item[i]))
const key = item[i]._
if (key === 'childrenArray') {
itemObj[key] = toObjArray(item[i + 1].dict.map(item => item.$$))
continue
}
const val = item[i + 1]._ || (['true', 'false'].includes(item[i + 1]['#name']) ? item[i + 1]['#name'] === 'true' : '')
itemObj[key] = val
}
return itemObj
})
}
function toXml(node) {
if (!node.name) return ''
const name = node.name.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
return `<outline title="${name}" text="${name}" ${node.rss ? `type="rss" xmlUrl="${node.rss}"` : ''}>
${(node.childrenArray || []).map(toXml).join('\n')}
</outline>`
}
@mhart
Copy link
Author

mhart commented Oct 13, 2019

Instructions (must have node installed)

mkdir -p ~/Downloads/plistToOpml
cd ~/Downloads/plistToOpml
# Copy the above file, plistToOpml.js into the ~/Downloads/plistToOpml directory
npm install xml2js
plutil -convert xml1 ~/Library/Application\ Support/NetNewsWire/Subscriptions.plist
node plistToOpml.js > exported.opml

Then import that opml file in NetNewsWire 5.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment