Action

Add to NotePlan Note

Posted by @derekvan, Last update over 4 years ago

Reads list of NotePlan file names from a file, then sends draft text to that note via prepending. Or, allows you to name a new file which is created in NotePlan with the draft text added. New note name is then saved to Project list file and read into the menu when you next run the action. This way you can add new notes without having to manually update the prompt.

To get started with this action:
1. Run the Drafts action for the first time and type “Testing” (or whatever your want) into the text box. This will create a file called “noteplan-projects.json” in your Drafts iCloud Drive folder. You can edit the script on lines 4 & 32 to change the name or location of this file (so long as it resides within the Drafts iCloud Drive folder–you can’t move it from there). It will also create a new note in your NotePlan app called “Testing”, which you can delete. (sometimes there seems to be a bug on Mac at least where if NotePlan isn’t open when you run the action, the x-callback command is ignored)
2. Open the “note plan-projects.json” file in a plain text editor (like VS Code, Bbedit, whatever). It should have this content:
[“Testing”]
3. Edit that file to include the names of your other notes. Enclose each name in quotes and add a comma between them. Like so:
[“Home”,“Work”,“Hobbies”,“Movies”]
4. Save the file and close the text editor
5. Now, when you run the Drafts action, you should see those note names show up as options you can choose in a menu. When you choose one, it sends the text of the current draft to that note by prepending.

Steps

  • script

    // Send to specific NotePlan note
    
    let fmCloud = FileManager.createCloud();
    var file = fmCloud.readString("noteplan-projects.json");
    
    if (file)
    {
        var json = JSON.parse(file); 
    }
    else
    {
        var json = [];
    }
    
    
    var p = Prompt.create();
    p.title = "Prepend to Which File?";
    
    p.addSelect("s","",json,[""],false);
    p.addTextField("n","New File?","");
    p.addButton("OK");
    
    if (p.show())
    {
        if (p.fieldValues["n"])
        {
            let safeTasks = encodeURI(draft.content);
            let safeTitle = encodeURI(p.fieldValues["n"]);
            json.push(p.fieldValues["n"]);
            json.sort();
            let output = JSON.stringify(json);
            let success = fmCloud.writeString("noteplan-projects.json",output);
            let noteURL = "noteplan://x-callback-url/addNote?noteTitle=%23%20"+safeTitle+"&text=-%20"+safeTasks;
            app.openURL(noteURL);
        }
        else if (p.fieldValues["s"])
        {
            let safeTasks = encodeURI(draft.content);
            let safeTitle = encodeURI(p.fieldValues["s"]);
            let noteURL = "noteplan://x-callback-url/addText?noteTitle="+safeTitle+"&text=-%20"+safeTasks+"&mode=prepend";
            app.openURL(noteURL);
        }
    }

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.