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 for Mac – an update

I’ve been mentioning a desktop version of Trunk Notes for Mac for some time now. Work has started, although is progressing a little slower than many of you would like. I thought a quick update on the current status of this project would be worth posting about – hopefully to reassure some of you that this is happening!

I want to keep the desktop version as simple as possible – whilst offering all of the power that Trunk Notes offers in iOS. Every page in your wiki will be represented by a plain text file on your computer. There are no propritory formats, no data lock in. If you need to use your information in something other than Trunk Notes then that will be made as easy as possible.

Here is what Trunk Notes for Mac currently looks like when started:

Trunk NotesScreenSnapz002

Most of the interface is taken up with the current page being used. When searching the wiki a pane opens with the search results. At the moment just the page name is displayed, however other information will be shown in the final release. As with the iOS version searching happens as you type. Here you can see that the word Journal is being searched for – and a number of wiki entries match.

You can quickly switch between viewing the rendered page and the Markdown. A keyboard shortcut or a click on Markdown will switch to that view. When you switch back again or choose a new page your changes are saved automatically. The plan is to automatically version any changes on save.

In the window title bar you can see the proxy icon (the tiny icon next to the page name). Drag this to another application, such as TextEdit or MacVim, and the Markdown of the current page will open in that other application. This kind of data transparency isn’t seen in many other desktop note taking apps – with Trunk Notes it will always be obvious where your data is.

The current version hasn’t implemented many of the Trunk Notes functions. You can see above that the timestamp function, numnotes, tagcloud and random are not yet available. However the {{image}} function is being used to show the cat image.

The interface is designed to be similar to that of a web browser. You can click the links and use the back/forward buttons in the toolbar to navigate your history.

Here you can see that an encrypted note has been requested:

Trunk NotesScreenSnapz003

With the Easter weekend coming up I hope to implement a lot more before sending out a test version to those kind enough to volunteer for beta testing. Trunk Notes is a part time project with most of my working week devoted to the company One Result where I work on some fantastic iOS apps. However despite that in the next couple of weeks I will be added a page inspector to manipulate tags and view information about pages, additional toolbar buttons, some of the main {{ }} functions and adding pages by dragging text to the app icon.

So, still early days yet in terms of how far I’ve got – but hopefully by the summer there should be a first release of Trunk Notes for Mac.

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