Skip to content

Instantly share code, notes, and snippets.

@JulianKniephoff
Created September 5, 2012 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JulianKniephoff/3630784 to your computer and use it in GitHub Desktop.
Save JulianKniephoff/3630784 to your computer and use it in GitHub Desktop.
VoodooPad Random Page Script Plugin
===================================
A script plugin to add an essential missing feature to the personal desktop
wiki VoodooPad: opening a random page.
Just hit the button in your Plugins menu to open a page randomly picked from
your current document. Every page has an equal probability of appearing;
independent of how many aliases it has. Also this plugin does not pick the
files you store in your VoodooPad document.
Installation
------------
First of all make sure you have the most recent version of VoodooPad. I created
and tested this exclusively using VoodooPad Version 5.0.3. Due to some changes
in the plugin programming interface this plugin may require at least Version 5.
Now just copy the contents of Random Page.jstalk into an empty page of any
VoodooPad document and then hit Plugin -> JSTalk -> Save Page as JSTalk Plugin…
in your menu bar. Give it a descriptive name (like Random Page.jstalk), which
will appear in your Plugin menu from now on. After pressing the Save button,
you may delete the page you just created.
Expert users just copy Random Page.jstalk to ~/Application
Support/VoodooPad/Script Plugins and remember that the filename (without the
extension) will be the name of the new menu item in the Plugins menu.
function main(windowController, document) {
var titles = pageTitles(document);
document.openPageWithTitle(
titles[
Math.floor(Math.random() * titles.length)
]
);
}
function pageTitles(document) {
var pageTitles = [];
var page = 0;
for(key = 0; key < document.keys().length(); ++key) {
var item = document.pageForKey(
document.keys()[key]
);
if(!isAlias(item)) {
pageTitles[page++] = item.displayName();
}
}
return(pageTitles);
}
function isAlias(page) {
var PAGE_ALIAS_TYPE = @"com.fm.page-alias"
var FILE_ALIAS_TYPE = @"com.fm.file-alias"
var uti = page.uti();
return(
uti.isEqualToString(PAGE_ALIAS_TYPE)
||
uti.isEqualToString(FILE_ALIAS_TYPE)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment