Trunk Notes 2.6.2 – minor Lua change

I have just submitted a minor update to Trunk Notes. In addition to a long overdue fix to sound recording (and support for a compressed format for much smaller recordings) there has been a minor update to Lua.

Lua scripting now knows some basic information about the device it is running on. This was prompted by users asking whether they could have different CSS files for the iPad and  iPhone. With this new Lua feature it should be simple to add this with a little bit of scripting.

Here is the excerpt from the manual describing this new feature:

Lua has access to some information about the device Trunk Notes is running on. This can be useful for customizing your wiki depending on whether it is running on your iPhone or iPad.

A device table in the global environment has the following fields:

  • name – e.g. Matt’s iPad
  • systemName – e.g. iPhone OS
  • systemVersion – e.g. 5.1.1
  • model – e.g. iPad
  • localizedModel – if your locale defines a different name for the device.

For example:

if device.model == "iPad" then
return "This is an iPad!"
else
return "This is not an iPad"
end

Trunk Notes scripting

Trunk Notes 2.6.0 is nearly ready for some final testing and release. It is quite a bit speedier than previous versions of Trunk Notes (especially for those with large wikis) and now has it’s own scripting language.

Adding scripting to Trunk Notes makes it even more powerful. Users can now do things in Trunk Notes that could previously only be done in desktop editors. Whilst this is only a starting point there are still lots of things to play with.

The scripting language built into Trunk Notes is Lua, a language ideal for embedding into applications. It is a very small, fast and powerful language which is easy to use and has lots of exciting features. Check out the Lua website for more information.

To whet your appetite here are a couple of examples of Lua scripts in Trunk Notes.

Day/Night example

There are a number of users who have experimented with JavaScript solutions to have Trunk Notes automatically switch between two stylesheets depending on the time of day.

Using the new Lua scripting it becomes possible to do this much more easily – and elegantly.

In my Header page, which gets included in every document, I add a call to a Lua script which will include the relevant stylesheet:

{{lua DayNight.lua}}

This will run the commands contained in the page DayNight.lua and insert the result into the current page.

Here is my DayNight.lua page:

hour = tonumber(os.date('%H'))
if hour < 7 or hour > 20 then
    return "{{stylesheet Night.css}}"
else
    return "{{stylesheet Day.css}}"
end

As you can see anything returned from Lua is treated as Markdown and included at the point where the script was called.

Manipulating the wiki

What you couldn’t do in JavaScript, even if you tried really really hard, was create new wiki entries. This is now almost trivial. An example:

-- Create a new wiki page (if this page already exists the new_page will be nil)
new_page = wiki.new('MyNewPage')
-- Put the date in the contents of the page
new_page.contents = os.date()
-- Tag this as Journal and Lua (tags are created if necessary)
new_page.tags = {'Journal', 'Lua'}
-- Save the page
wiki.save(new_page)
-- Return the page name
return new_page.title

There are also Lua functions for searching the wiki, getting lists of tags and retrieving existing pages. Arguments can be passed to scripts, e.g. {{lua ExampleScript.lua, argument 1, argument 2}} and retrieved through the args array.

Scratching the surface

I’m looking forward to see what new and innovative uses the Trunk Notes community makes of Lua scripting. Trunk Notes 2.6.0 is going through some final testing now before it is submitted to Apple next week (probably).

Keep having fun with Trunk Notes – stay productive!

(Lua scripting will play a big part in making Trunk Notes for Mac a powerful wiki to have on your desktop. Watch this space!)

Trunk Notes 2.5.7

Christmas is approaching and so is a new release of Trunk Notes. It is currently in the Apple approval queue along with countless apps for the holiday season – which is why it’s not quite on the App Store yet.

There are four main changes in this release. Two new functions and some custom stylesheet enhancements.

The new functions are prefix and search. These allow you to search for and display lists of matching pages.

Lets say you want a list on your HomePage of all pages whose title starts with Meeting. Simply add {{prefix Meeting}}. If you use namespaces to separate parts of your wiki this can be used to create mini contents pages for each section.

The second new function is search. As you might guess this produces a list of notes by searching the notes for a specific word or phrase. For example {{search Trunk Notes}} will give you a list of all pages containing the phrase “Trunk Notes”.

The other two changes are both related to CSS. CSS is how web pages (and pages in your Trunk Notes wiki) determine what styling (fonts, colours, etc) to use.

The first change is how the {{stylesheet}} function works. In previous versions of Trunk Notes if you wanted to specify a stylesheet for use on a particular page, e.g. {{stylesheet HomePageStylesheet}} then that stylesheet had to include all of the stylesheet information needed to display the page sensibly. This was true even if all you wanted to do was change the font to be slightly larger. In 2.5.7 {{stylesheet}} adds the styles on top of the main stylesheet.

For example if I wanted on my HomePage to make the font smaller so that more information could fit I could create a new page called HomePageStylesheet and in that add the text:

body {
    font-size: 14px;
}

Then add {{stylesheet HomePageStylesheet}} somewhere in HomePage. This makes it much easier to create styles to be used only on specific pages.

Related to this change is the ability to define styles which get applied to pages with certain tags. If you have a page with the tag “Large Font” you can now use a CSS class .tag-largefont to define how you want the content to look. For example:

body.tag-largefont {
    font-size: 18px;
}

Hopefully Trunk Notes 2.5.7 will be in the App Store any day now – as soon as Apple have reviewed all of the Christmas Cracker apps sitting ahead of it in the queue!

Using IconProject with Trunk Notes

20111115-211134.jpg

A quick post about IconProject and how you can use it with Trunk Notes. IconProject is an app which allows you to add icons to your iPhones home screen which launch URLs (no jail breaking required!) The URLs can be any URL you want, include the special URLs to Trunk Notes pages.

The app is easy to use and creates really nice looking icons.

In the above screenshot I used it to create an icon which takes me straight to my passwords note.

You can link to any Trunk Notes page. A link to a Trunk Notes page starts with tn://. As well as normal pages you can also use URLs to create new pages.

  • tn://Special:NewText
  • tn://Special:NewImage
  • tn://Special:NewCamera

It’s quite cool to be able to have an icon on your homepage which takes a picture with the camera and adds it straight into your personal wiki.

More information about IconProject

Naming Pages in Trunk Notes

Unlike many note taking apps Trunk Notes forces you to give each page a name. That is because Trunk Notes, at it’s heart, is a personal wiki. The power of a personal wiki comes from the ability to link named pages together. Having good names for pages makes this easier and more natural.

Page names are also used to help find information quickly. The search bar in Trunk Notes works by matching what you type against existing page names. Start typing ‘blog’ and all pages which start with Blog will be listed with the most recently modified at the top.

Prefixing page names can be a helpful way to organise wiki entries. I am writing this blog post in Trunk Notes on my iPad. It’s name is ‘BlogNamingPages’. All my other blog posts also start with Blog. To find all my blog posts ordered by when they were written I just type Blog in the search bar. I don’t do this for all pages, just those where searching is quite common – this includes recipes.

One aspect of Trunk Notes which some new users find awkward is the “no spaces in page names” rule. This was an early design decision and it’s aim is to make it easier to refer to pages. You can still create links which contain spaces, for example [[Blog naming pages]] will show as written but still refer to the page BlogNamingPages. Trunk Notes makes this rule easy to follow by enforcing it. If you type “my new page name” Trunk Notes will correct it to “MyNewPageName”.

 

Most of the time you should give your page an explicit name when creating it. The exception is if you are using Trunk Notes for journalling or another activity where having the current date as the name is acceptable. If you tap the Action button and then use New… to create a page you will find that the name of the page is the current date. The format for this is taken from the timestamp settings.

In summary, names are very important in Trunk Notes. Think about page names carefully and you will be rewarded by information which is easy to link together and search.