Gmail to Evernote messages now in Sent mail

The Gmail to Evernote script works by sending a message to your Evernote email address. It does so using Google Apps Script. Until recently, a message sent by Google Apps Script would not appear in your Sent mail; in many cases, this would be considered an omission, and it has been fixed now: the messages will show in your Sent mail.

For messages sent to Evernote, keeping a copy in your Sent mail is less relevant; several people, including myself, considered it a benefit that these message were not cluttering your Sent mail. I will therefore look into the options for not getting receiving a copy of the mail to Evernote in your Sent mail, perhaps as an option that you can switch on or off. No immediate solutions have come to my mind yet, but if I get some, it will be implemented in the next version.

Meanwhile, any bright ideas are welcome!

Update: the bright idea is to create a filter in Gmail, specify your Evernote address in the To field of the search criteria, and select Delete it as action (submitted by Nathan Stretch, comment below).

Multi-day calendar events in Google Apps Script

You can create events using the Calendar Class in Google Apps Script. However, only for regular (not all day  events) you can set both the start and the end time. For all day events, you can only set one date, so they will always be one day only. Then how can you create all day events?

There are a few workarounds:

  • Create a regular event and set the start and end time to midnight; remember to specify midnight of the day after the end day. The drawback is the event fills the whole space for a day in your calendar overview, rather then just a line at the top as with all day events.
  • Create a all day event series, so you have a sequence of one-day all day events; this looks already a bit nicer, but in the calendar view, from a single event yio can not see how long it last.
  • Create an event from a description, this creates real multi-day all day events.

So creating an event from a description seems the best way to go. This is worked out in a new function, createMultiDayEvent( calendar, title, startDate, endDate ). Continue reading

New version of Gmail to Evernote script

Version 3 of the Gmail to Evernote script has been released. Existing users will have to authenticate and give access again, to keep  the script running. You can do so easily by going to  gm2en.com.

This is the new web interface, that is one of the major changes in the new version. All options can now be configured from this form.

Other changes are:

  • more flexibility in selecting labels: you can now specify a different label than ‘Evernote’, to select the messages to be forwarded. Also, you can select a tag label, and only this label and its sublabels will be included as tags to be sent  with the message to Evernote, other labels will be ignored. Finally, you can specify a label to be assigned if a message is sent to Evernote.
  • better catching of errors. it may happen, that a server is not reachable. Before, you would receive a notification of script failures, but these are caught now and you will not receive a notification anymore, After all, you can not do anything about it, so it does not make sense to send these messages. Other problems, such as the requirement for re-authentication, will still be sent. 

.All options are documented in the original Gmail to Evernote post, which has been updated.

Address unavailable: http://gs.harryonline.net/gm2en.json ?

Users of the Gmail to Evernote script may have received a “Summary of failures” message today reporting the following error:
Address unavailable: http://gs.harryonline.net/gm2en.json (line 180, file "Code")
The server, from which this file is read, has been down for a number of hours yesterday, so you got these error messages.

Why is the script reading this file, it is only supposed to forward messages from  your Gmail account to Evernote? It has to do with version information, to be able to inform you about new versions.
Continue reading

Stylesheets in Google Apps Script UiApp

Despite the documentation, it is quite well possible to use style sheets in a Google Apps Script UiApp.

The documentation of Google Apps Script is quite clear: “… there is no way to use custom style sheets in UiApp.”. This is mentioned in relation to the stylename methods, such as setStyleName(). However, most elements in the UiApp have the  setStyleAttributes() method. This accepts an object with style attributes, e.g.

label.setStyleAttributes({background: "black", color: "green"});

This is how you can assign style information to an element.

The essence of a style sheet is to separate the formatting from the content and the program logic. Separate style sheets make the script more readable and enable you to change the appearance and layout of all pages in a UiApp, just by editing one single file.

In Google Apps Script, you can realize this by setting the style attributes using named objects, and define these objects in a separate file. The following example shows how this works.

Continue reading

ObjDB: the easy way to store data with Google Apps Script

There are various ways in Google Apps Script to store data, a common way is to store data in a spreadsheet. Spreadsheet data is relatively easy to access, and sample code is provided to read data from a spreadsheet into an array of JavaScript objects, and to write from objects to the spreadsheet. For more advanced database functions (update, select, delete), you have to do some more programming.

For larger applications, you may want to use MySQL or other databases via JDBC, Again, some sample code is provided, but this time not to read/write to and from JavaScript objects. A lot more coding is required, especially to link the fields in each record to the field name, instead of just the offset in the results rows.

To make it easier to work with data in Google Apps Script, both from spreadsheets and from JDBC databases, I have developed the ObjDB library. This is a set of functions, with which you can open a spreadsheet or database, and do all the basic operations: select, update, insert, delete. Functions are the same for spreadsheets and for JDBC databases, except the different parameters for the open() function, so if you start with data in a spreadsheet, and later move the data to a database, there is hardly any code to change.

To show how the library works, I prepared a demo spreadsheet with script. Open the link, it should create a new copy of the spreadsheet, if not, copy it yourself. Then go to ToolsScript editor…, and run any of the functions to see it in action.

Note that the script in this spreadsheet includes the objDB library, see under ResourcesManage Libraries….

For more documentation, reference and source code, go to http://googlescripts.harryonline.net/home/objdb.

How to index Project Gutenberg files

project_gutenberg_logoProject Gutenberg offers over 40,000 free ebooks: choose among free EPUB books, free kindle books, download them or read them online. Recently, they have added support for Dropbox, so you can download ebooks directly to your Dropbox account. It will create a folder ‘Apps/gutenberg’, and will store all ebooks in that folder.

After a while, this Dropbox folder will have a long list of files, all with names like pg1234.epub and pg5678-images.epub. They have some meaning, but which file contains which title? Of course, you can rename each ebook  after downloading, but this is extra work, and I want a smart solution.

pg_filelist

So I created a script to create an index for all ebooks–at least, for those in EPUB format. Now there is simply an index.html file, which will open in any browser. It shows the file name, together with the creator, title and language. Depending on how you view the index.html file, the links may be clickable, In any case, you can quickly see which file is which book.

pg-index

The script works on any set of EPUB file, but usually, they will have a more meaningful name and there will be less need for a script like this.

Continue reading

Send Gmail to Evernote: an overview of the tools

Updated 28 June 2013: both Evernote Web Clipper and Powerbot have new versions, the table refers to these new versions.

In the creation and development of the Google Apps script to send Gmail messages to Evernote, I have looked around what other tools are available. These are the other tools that I found:

  • forwarding to the Evernote email address and using the InQloud service;
  • the Evernote Web Clipper (only tested on Windows/Chrome);
  • PowerBot, an extension for Chrome (also others versions available, e.g., for Firefox and Safari)
  • IFTTT and Zapier, tools that enable you to connect between other web services

I have looked at how well these tools keep the formatting of the message, whether they keep attachments, have a link back to the message in Gmail, whether they can be automated using Gmail filters, and whether you can select the notebook or tags, and edit/comment on the message before sending.

Continue reading

New version of Gmail to Evernote script creates link to Gmail in Evernote

Version 2 of the Gmail to Evernote script has been released. The new version adds text on top of the message in Evernote, with the basic headers from the email message (From, To, Date) and a link back to view the message in Gmail. For example, if you forwarded the message to a task list in Evernote, you can now quickly send a response after completing the task. No more searching in Gmail to find the message back!

There are more changes, and you have to do some extra configuration steps if you use multiple sign-in for Google, because in that case, the link to the Gmail message is not always correct.

This version will send email notifications when a new version is available. If you are running the script directly from bit.ly/gmailevernote, you don’t need to update, and you will not receive a notification, unless some other action is required or relevant information can be given.

If you made your own copy of the script, you will always receive a notification of new versions, so you can replace your copy with the new version.

You may have to authorize and grant access again, see the previous update on Gmail to Evernote.

Continue reading

Sprintf: merge text and variables in Javascript

The function sprintf is common in many programming languages, as a way to merge programme variables in a text string. It has good options for formatting, such as outlining text string, or setting the precision of numbers. In many cases, you don’t need those, and a simple function that just inserts the variables at the right place is fine, and a better option in order to keep your JavaScript code short. See the example below:

// Simple string concatenation
var html1 = '<a href="' + url + '">' + link + '</a>';

// Using sprintf
var html2 = sprintf( '<a href="%s">%s</a>', url, link );

In this article, I share a simple function doing string replacements. For sprintf alternatives with the full functionality, just Google on ‘javascript sprintf’, and you will find some good versions. If you don’t need all that, read on.

Continue reading