Script Examples?

Could anyone point me at a few example scripts, preferably well commented with what they’re meant to achieve and how they work, please?

I’m new to Notenik having only downloaded it a few days ago and have been ploughing through the knowledge base to try to get to grips with it. I’m finding the documentation on scripts father confusing and unfortunately the KB doesn’t have any code snippets to illustrate language usage.

I’ve been using TinderBox for a while, but have hit problems with its reliance on XML for storing information and am hoping that Notenik may be an adequate substitute for my needs. One thing I need to be able to do is pull information from related notes and process it, or at the very least format it into a temporary CSV file and pass that to another application for processing (likely an R script).


Welcome to Notenik, and to the Discourse community!

You make a great point. I’ve been working on a few scripting enhancements of late, and have noticed that the documentation is lacking examples, and probably pretty difficult to parse. I’ll try to improve that in the next release or two.

In the meantime, the new Query Builder function is a quick and easy way to generate a basic merge template and a script to do sorting and filtering. You can then edit the generated files to use as examples of how you might build your own.

I use Notenik to generate several websites, and I know @ThePrinter has sometimes looked at the scripts and templates there. For example, look in the scripts folder for the Notenik Website itself.

See attached for an example of a simple script to write the contents of a Collection out to a csv file.
Script Output to (8.8 KB)

Of course, you can always just export to a csv file as well.

Thanks, I shall study these tomorrow (I’m in the UK and it’s getting late).

Also see the improved scripting documentation, along with a scripting sample, in the 10.0.0 release that’s just out. Let me know if this is helpful!

Thanks, I’ve downloaded v10 and plan to take a look at the new docs as soon as I’d practicable. The example you attached to your last post has proved a useful start, so thanks for that too.

There’s one thing that perhaps you could confirm. Scripts are intended to be used with templates, the script acting as a query to select the data that is output according to the template format. The scripting “language” of functions (defined by a module + action + modifier) and arguments (object and value) was designed solely for that purpose; it’s not a scripting language in the sense that Python is, or indeed Tinderbox’s Action Script. If I want to process note data in anyway — for example to derive information from that held in one or more records (i.e. notes), I need to output it (say as CSV or JSON) and do the processing externally.

This raises a further question. What’s the easiest way of launching an external process? Or is it best done the other way around, having the external process (say a shell or Apple script) tell Notenik to run a query (expressed as a script) and pipe that to further script that runs the desired calculations?

As an aside, did you ever consider embedding a full blown interpreter like Guile (GNU’s implementation of Scheme) or Lua in Notenik?

Thanks again for your efforts and help.

Yes, I can confirm your understanding of the scripting function in Notenik: it is not a general-purpose scripting language, and is mainly of use for sorting and filtering data before feeding it into a template. And no, have not considered embedding a full blown interpreter into Notenik.

And yes, probably best to invoke Notenik scripting from an external process. The latest version of Notenik has a custom Shortcut action that can be used in just that way.

@hbowie Thanks! I’ve got a much clearer picture of how to go about things now.

See this new entry for a fairly straightforward scripting example.