changing the date format
I'm using the following code from Voodoopad Page Events:
function pageWasCreated(document, item) {
var attString = item.dataAsAttributedString();
attString.mutableString().appendString("\nThis page was created on " + (new Date()));
item.setDataWithAttributedString(attString);
}
However, this produces:
This page was created on Wed Aug 29 2018 16:33:02 GMT+0100 (BST)
I want to change the date format to:
This page was created on Wed Aug 29 2018 16:33:02
How do I change this?
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Sarah on 29 Aug, 2018 10:11 PM
Try this:
This should give you the second date format. Let me know if you run into any issues.
2 Posted by svs on 31 Aug, 2018 08:05 AM
Many thanks, but this still returns:
3 Posted by Sarah on 31 Aug, 2018 03:14 PM
Did you remove the previous script completely from the VPPageEventScript? If so, have you tried closing and reopening VoodooPad, and then attempting to create a new page?
4 Posted by svs on 31 Aug, 2018 04:02 PM
Yes tried that and still no joy. My VPPageEventScript contains the
following:
function makeOrphanedPage(document) {
var linkedPages = {}; // using a hash table here because it's
convenient.
var orphanedPages = [];
var summaryPageName = "Orphaned Pages";
/* Collect all linked pages. */
var keys = document.keys();
for (i = 0; i < keys.length; i++) {
var page = document.pageForKey(keys[i]);
if (!page.isText() || (page.key() == "orphaned pages")) {
continue;
}
var pageContent = page.dataAsAttributedString();
var linkedPageNames =
document.linkedPageNamesInAttributedString(pageContent);
for (j = 0; j < linkedPageNames.length; j++) {
linkedKey = linkedPageNames[j].vpkey();
// ignore self links.
if (!linkedKey.isEqualToString(page.key())) {
linkedPages[linkedKey] = "";
}
}
}
/* Now compare the linked pages with all pages to find the orphaned
ones. */
for (i = 0; i < keys.length; i++) {
var key = keys[i];
if (linkedPages[key] == null) {
orphanedPages.push(key);
}
}
/* Create a summary page and open it. */
var summaryPage = document.createNewPageWithName(summaryPageName);
summaryPage.setDataAsString(summaryPageName + "\n\n" +
orphanedPages.join("\n"));
}
function pageWasOpened(document, page) {
if (page.key() == "orphaned pages") {
makeOrphanedPage(document);
}
}
function pageWasCreated(document, item) {
var attString = item.dataAsAttributedString();
attString.mutableString().appendString("\nThis page was created on
" + (new Date().toString()).replace(/ \w+-\d+ \(.*\)$/,"")));
item.setDataWithAttributedString(attString);
}
and a new page returns:
This page was created on Fri Aug 31 2018 17:02:17 GMT+0100 (BST)
5 Posted by Sarah on 31 Aug, 2018 08:20 PM
Do you have any other event script pages within that document?
6 Posted by svs on 01 Sep, 2018 09:41 AM
No, just the one: https://d.pr/i/G6kIkH
7 Posted by Sarah on 04 Sep, 2018 01:11 PM
I see. What version of VoodooPad are you currently using? And which device and macOS version?
Does anything change if you delete the current VPPageEventScript and create a new one with the above script?