Google Apps Script And Calorie Counting

It’s in the news lately that by 2030, 50% of the population will be obese. Well, I’m a bit (ok, maybe more than a bit) overweight now and was looking to do something about it. So for my diet, I’ve started counting calories. I’ve tried a number of other diets with mixed results, but calorie counting for me always works. However, counting calories can be a bit of a pain. There are a number of ways to figure out how many calories are in things, such as the container the item comes from, websites like http://caloriecount.about.com/, http://fatsecret.com/ or search on your favorite search engine. Finding out the calorie content of a food isn’t really so much of a problem in and of itself because after awhile you just know how many calories are in the usual things you eat. But where is the best place to keep track the current running total for the day? It has to be easily accessible to me or I don’t do it. I don’t always have paper, nor am I in places where I have connectivity. Android, Gmail and of course, Google Apps Script to the rescue!

Counting Calories using Apps Script


The process is simple. I send an email to myself with the subject “@FOOD” where the body contains the number of calories in the food and the name of the food, one per line. I wrote a script which, every 15 minutes, scans my email and computes the total of calories I’ve consumed in the last 24 hours and updates a spreadsheet with the total.

Why do it this way? Using Gmail for the recording makes it so if I’m offline on my phone, the gmail app will send it when I’m online. Putting it in a Google spreadsheet means I can make a shortcut for it in chrome, and a desktop web shortcut icon on my Android phone for easy access. Additionally, using a spreadsheet allows me to perform other calculations, make charts, etc.

How do you set it up?

First create a new spreadsheet, and click on Tools > Script Editor. Click on File > New > From Script Template. Search for “Calorie Counting” and you will be able to locate the script. Then, click Install and you are all set. Save the script, run it, at which point you’ll get two authorization dialogs, click ok through them. Run it again to make sure it populates the sheet properly. Then, in the script editor, click Triggers>Current script’s triggers and add a new trigger:

And you’re all set! Your spreadsheet, after the script runs will look like this:

From here the possibilities are endless. I’m thinking I could make a UiApp script which uses the new Charts bean to draw a graph. Perhaps make a service to view/change calories because I mess things up every once in awhile. You could also add code for “@WEIGH” messages to track weight and could graph that too. Your imagination is the limit! And if you have an even better idea for how to use Apps Script to improve Gmail and Spreadsheets, you can post it to our Gallery (Script Editor > Share > Publish Project) to share with the world.

The technology in crisis

In many ways, the arrival of Hurricane Irene last week drove home the importance of National Preparedness Month, an effort from the FEMA Ready campaign to encourage Americans to take steps to prepare for emergencies throughout the year. With people relying on the Internet worldwide, it’s not surprising that Google search data and a recently released American Red Cross survey show that people turn to online resources and tools for information and communication during major crises. First responders, who provide services in the aftermath of disasters, are also finding Internet and cloud-based tools and information useful—for improving their understanding of a situation, collaborating with each other and communicating with the public.

Today, in preparation for September’s National Preparedness Month, our Crisis Response team is introducing a new Google Crisis Preparedness website with information and educational tools on using technology to prepare for crises. On the site, you can see how individuals and organizations have used technology during crises in the past, including how two girls located their grandfather after the Japan earthquake and tsunami in March of this year and how Americorps tracked volunteers during the tornadoes in Joplin, Missouri in May of this year. There’s a section for responders with information on using Google tools in crises, such as collaborating efficiently using Google Docs, Spreadsheets and Sites, visualizing the disaster-related information with Google My Maps and Google Earth, and more.

Also, you can access a new public preparedness web resource launching today: Get Tech Ready, developed as a collaboration between FEMA, the American Red Cross, the Ad Council and Google Crisis Response. There, you’ll find tips on using technology to prepare for, adapt to and recover from disasters, for example:

  • Learn how to send updates via text and internet from your mobile phone in case voice communications are not available
  • Store your important documents in the cloud so they can be accessed from anywhere or in a secure and remote area such as a flash or jump drive that you can keep readily available
  • Create an Emergency Information Document using this Ready.gov Emergency Plan Google Docs Template, or by downloading it to record and share your emergency plans and access them from anywhere

We encourage you to take a moment now to see how simple, easy-to-use and readily-available technology tools can help you prepare for a crisis. You’ll be more comfortable using these tools in the event of a disaster if you’ve already tried them out—and even integrated them into your daily life.

Google Apps Script: New ways to deliver workflow solutions for businesses

Google Sites offers an incredible way to author and distribute content, and we use it extensively both for ourselves and our clients. Therefore it was not surprising that our customers started requesting a content approval workflow in Google Sites. Now with Google Apps Script, we have been able to develop Appogee Content Approval for Google Sites.

The Solution
Appogee Content Approval for Google Sites (ACA) can be set up for any existing Google Site without having to make any changes to the site. ACA works as follows:

  1. The ACA spreadsheet generates a Content Submission Form and any content submitted is routed to a selected approver.
  2. The approver receives an email notification, which they can authorize or reject.
  3. Once authorized, the ACA spreadsheet writes the new content into the target Site using Apps Script’s Sites services. The new content is then visible to anyone with view permissions in the target site.
Approver receives an email containing the submitted content

 


 
The content submission URL can be shared to any group or published directly on the target Google Site, which represents the end goal on the workflow diagram below. Content may only be submitted by users that are logged into your domain and content can only be published with Approver sanction.

ACA Workflow Diagram
Google Apps Script made it easy

We used a number of Apps Script services to develop this application. Apps Script was an easy choice as it builds on pooled knowledge from the Google Web Toolkit (GWT) and uses Javascript syntax. Using Apps Script’s UI Services, we were able build up a working user interface quickly. Google has since introduced a new experimental feature to complement the UI Services, which provides a drag and drop GUI for building screens. We expect this feature to reduce development time required for building future apps, as well as offering a wide range of widgets and controls to improve the user experience. We used a standard Google spreadsheet as a kind of a data store in ACA. It’s worth mentioning that Apps Script’s documentation site has a plethora of tutorials covering everything from simple spreadsheet macros to full help desk applications.

One of Google Apps Scripts’ core features is the ability to seamlessly integrate different services together, in our case this was Google Sites and Spreadsheets, but many other services are accessible, such as Mail and Contacts. It was always the aim to make ACA a powerful tool without unnecessary complexity and thanks to Google Apps Script, we have successfully delivered content approval workflow to Google Sites.