Last active
January 4, 2016 08:19
-
-
Save levity/8594322 to your computer and use it in GitHub Desktop.
editing a page with VoodooPad API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Page = function(key) { | |
var page = document.pageForKey(key), | |
data = page.dataAsAttributedString(), | |
text = data.mutableString(), | |
changed = false; | |
this.write = function(msg) { | |
changed = true; | |
text.appendString(msg); | |
}; | |
this.save = function() { | |
if (changed) | |
page.setDataWithAttributedString(data); | |
}; | |
return this; | |
}; | |
var Log = { | |
write: function(msg) { | |
NSApplication.sharedApplication().delegate().console(msg); | |
} | |
}; | |
function testTimestampChange() { | |
Log.write(document.pageForKey('test').modifiedDate()); | |
var page = new Page('test'); | |
page.write("foo"); | |
page.save(); | |
Log.write(document.pageForKey('test').modifiedDate()); // it changes | |
} | |
function main() { | |
testTimestampChange(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment