Track Flights to Google Sheets

Flight track from Paris to San Francisco

I built my ideal flight tracker from bitter experience. Planes, of course, leave late or arrive early. They often drop off tracking for an hour or more, especially on polar routes. You might also forget to download a track while exhausted after a long trip and then it's unavailable by the time you remember to go back and look at it.

This Google Apps Script project uses the FlightAware API to make this a hands off process. You just put your flights in a spreadsheet in advance and come home to a folder of tracking data. If a flight stops tracking, the script projects its path on a great circle route to the destination airport. When tracking comes back online the script recomputes the projected data to the new good location, leaving you with the best possible version of the data.

(I'm about to leave on a trip that will take me all around the planet - the third time I will have done this, and hopefully the first with an excessively accurate GPS track as a souvenir).

In Google Drive create a new spreadsheet with a Flights tab, and a folder to store the flight tracks. Sign up for the FlightAware AeroAPI and grab an API key. Check that you're comfortable with the pricing - I find it's pretty reasonable for personal use. Once that's ready, create a Google Apps Script project and paste the following script into Code.gs:

I'm not including the code here, but you'll also need this script for airport locations. Add an Airports.gs file to the same project and paste it in.

Edit Code.gs to add your API key, the configuration spreadsheet, and the folder for flight tracks.

Finally, run the setup function from the Apps Script debugger. You'll be prompted to authorize the script, and a sample row will be added to the configuration spreadsheet in the Flights tab. The script will also be scheduled to run every ten minutes. You can now add upcoming flights to the spreadsheet. Once you've got this far, I recommend adding a test flight to make sure everything is working before tracking something that you care about.

This is the first Apps Script project I've released that is 100% written by Claude Code - I didn't touch a line of it. I'm sharing because of my painful experience with flight tracks that didn't meet my needs, and the extensive product management process of smoking out edge cases and testing until I had a solution that really works. The image above is a test track from Paris to San Francisco (a randomly chosen flight while I was debugging) and it has two sections where data dropped - the end result captures the actual route as far as possible and I'm really happy with the result.

Enjoy, and leave any questions in the comments.

Workspace Studio and Read-only Sheets

By . Updated on

A Google Workspace Studio Flow

As an Apps Script addict I was excited to experiment with Google Workspace Studio. It's a no code automation tool in the typical flowchart style with the addition of Gemini, so you can use AI for decisions and text manipulation. Unfortunately it failed hard on my first task.

I have a spreadsheet that pulls in Google Fit data, and another one that combines that with other goals to create an overall lifestyle score. Occasionally I copy data from one sheet to the other and automating this has been on my todo list for years with absolutely no chance of getting to done. Workspace Studio should have made this easy.

Building the flow was straightforward, but the steps that write new data were flagged as being in an error state, although no actual errors were flagged in the configuration for the steps. Opening and closing the flow unsettlingly cleared the errors. I started the flow and hoped for the best, but got this error:

"Couldn't complete. Check that the spreadsheet is private and doesn't use the IMPORTRANGE function."

At first I thought this must be inverted and the sheet needed to be shared in some way... but no, it's true, you can only update a private sheet. Which is useful in a trees falling with no one watching kind of way.

I share this mostly because googling the error came up short (and the AI overview is unhelpfully talking about sharing the sheet). Workspace Studio is only a few months old and hopefully this limitation will be fixed. There are some nice features in preview, like webhooks, raising the prospect of handing over to apps script if the flow can't do quite what you need. This should be a nice piece of the AI automation puzzle as it matures.

Links for February 2026

By . Updated on

I'm following @ml@social.mitexleo.one. ∞


I'm following @retiolus@mamot.fr. ∞


I'm following @matokie@mastodon.social. ∞


I'm following @mikef@messydesk.social. ∞



Google Apps Script created by primary email (domain), and it opens the blank script in secondary (gmail)

This drives me nuts every time I open apps script and need to switch the account. #google #appsscript #gas



I'm following @AirlineReporter@avgeek.social. ∞


Image to 3D Asset with TRELLIS.2

This is cool, a Microsoft model to convert a photo to a 3D model. I ended up with a dog with two tails but otherwise pretty decent. #3d #ml #microsoft

Adding AI to Todoist with Google Apps Script and OpenAI

By . Updated on

An AI completes a task on a To Do List

This simple script adds useful AI to Todoist and runs in the cloud on Google Apps Script.

I use Todoist to run my life, and my dream is for it to be able to complete certain types of tasks for me. With OpenAI Operator and Anthropic Computer Use this is getting closer and closer to reality. Yes, there is a risk that Todoist spends all of my money on paper clips. But there is also the upside that it will eventually do my weekly shopping, pay my bills and call back the dentist's office. Google's new Ask for Me is promising too, even if right now it's just going to bother nail salons out of existence.

I already put together an Alexa replacement using a Raspberry Pi and the OpenAI realtime API. It switches lights on and off, adds things to my to do list, figures out when the next L is coming and more (I'll blog more about this soon).  One thing I learned is that this kind of thing can get pretty expensive. I can see why Amazon is procrastinating on an LLM Alexa. But costs keep going down, and the future will get more evenly distributed over time.

The first version of this script has two objectives. Respond to tasks, and create calendar events. Here's the script:

To get this working you need API keys from OpenAi and Todoist. Perplexity is optional, if you have a key add it at the top. It only works with tasks that have the right label, ai is the default - you can change this with AI_TASK_LABEL. I initially developed this with o1, but it looks like the tool use was rushed out too quickly and it calls the same tool repeatedly. GPT-4o works well enough and you can test switching out the model by changing OPENAI_MODEL.

Quick configuration guide - create a Google Apps Script project in Google Drive. Paste in the code above and add your API keys and any other desired configuration changes. Go to Project Settings in the right hand navigation and make sure your time zone is correct. Then go to Triggers and schedule the function trigger to run periodically (I use every 5 minutes). You should be done.

Back in Todoist add the ai label to a task (or whatever label you set in the script) and the AI will respond. With the current script there are two use cases - ask it to create an event (it can invite people, add details to the description, etc.), or ask it to research some aspect of the task you're working on. I think this is helpful because it has the full context of the task, and while you're working in Todoist it's useful to store the history there as well.

The point here is to extend the number of tasks that the script can take on. Add new tools for the AI to consider in the getTools() function, and then wire that tool into an implementation in generateAIResponse(). createCalendarAppointment() is a good example of using built in Google services - as well as the calendar it's pretty easy to interact with email, Google docs and many more. I'm planning to add file uploads as well, and will update this post with iterations of the script that add helpful functionality.

OpenAI recommends around 20 tools as the maximum. At that point it might be necessary to break this up into multiple assistants with different tool collections.

Let me know in the comments if you manage to use this to start crossing anything off your list.

Updated 2025-02-17 01:18:

Updated the script to support images and Perplexity.

Image support takes advantage of multimodal input. Any image attachments will be sent as part of the conversation. This uses the large thumbnail in Todoist by default. It supports JPEG, GIF, PNG and WEBP. If a thumbnail is not available it will send the full size image without resizing, depending on how large this might not be accepted by OpenAI.

Perplexity is implemented as a tool (so OpenAI is always called, and it may optionally call out to Perplexity to get more information). This is useful for web search, local search and knowledge past the training cutoff for the OpenAI model. It's optional, if you don't include a Perplexity API key then it just won't be used.

Here's a simple use case - add a photo of a book and ask Todoist to find the URL where you can order it on Kindle.

California Climate Credit

By . Updated on

Illustration of money in a burned out forest

Once in a while I'm stupid enough to read my email. This month I'm getting a climate credit! Must have done something right? No:

"The California Climate Credit is part of California’s efforts to fight climate change. This credit is from a state program that requires power plants, natural gas providers, and other large industries that emit greenhouse gases to buy carbon pollution permits. The credit on your bill is your share of the payments from the State’s program."

So... apparently part of fighting climate change is making my energy bill randomly cheaper?

It's hard to think of anything less likely to help. Just as I'm starting to feel the pain of winter bills I'm paying slightly less and so I'm slightly less inclined to turn down the heating or finally do something about my beautiful but effectively absent front windows.

A problem with carbon taxation is that it's regressive. So why not use this money to make the first $xx cheaper, and maybe even charge more at the high end of usage?

Pandemic Gas Mystery

By . Updated on

For no good reason I downloaded my gas and electricity consumption data by day for the last couple of years.

Electricity usage in kWh 2020 vs 2019 7 day moving average

The electricity trend is unsurprising. At the start of the pandemic it jumps up and stays up. With work and school from home we're running four computers non-stop, burning lights and (the horror) printing things. Overall we used 24% more electricity in 2020.

Gas usuage in therms 2020 vs 2019 7 day moving average

Gas on the other hand is pretty flat. There are some different peaks at the start and end of the year, but our total gas consumption increased by 0.08%. This doesn't make any sense to me. Being at home doesn't make much of a difference to laundry but it should have had a big impact on everything else. The heating has been on way more, we're cooking breakfasts and lunches that would have occurred out of the house in 2019 and we must be using more hot water as well.

There is one strange difference between how electricity and gas are metered. Fractional kWh are distributed randomly between .00 and .99 as you'd expect. Fractional therms are totally different - we're apparently likely to use 1.02 or 2.03 therms but never 1.50. This feels like it must be some sort of rounding or other billing oddness but I can't find any reasonable explanation despite asking Google three different ways.

Fractional therms billed distribution for PG&E billing days in 2019 and 2020

In a move that I might come to bitterly regret I have emailed PG&E to see if they can explain it. I'll update this post if I hear back. Or if you're a therm metering expert please leave a comment!

Updated 2021-02-20 13:51:

PG&E say:

"Thank you for contacting our Customer Service Center. Gas usage is registered by recording therms usage.  If you view your daily usage online, you will see that therms are only registered in whole units.  The only pace that you will see therms not as whole units is when you review the average daily usage.  The pandemic started in March 2020 and since then your gas usage is up slightly versus previous years. Most customers will see a larger increase in electric usage versus gas usage when staying home more than normal.  The majority of customers set the tempatures of the their heaters to very similar temperatures year over year and your heater will work to keep your house at the temperature whether you are home or not at home."

So the fractional therms are some sort of odd rounding on the downloaded data. Fair enough.

The majority of customers use the same temperature setting? Really? So that might be a good explanation if you constantly heat your house to the same temperature, but I know for sure that isn't us. We have a Nest Learning Thermostat and as I've previously reported this doesn't so much learn as just constantly turn the heating off. So staying warm is a constant battle with the thing.

Maybe the difference is that the pandemic started around Spring when San Francisco is warm enough to not need much heating. I'll look again when I can just compare winter vs winter in a couple of months.

Updated 2023-08-06 18:11:

Pandemic Gas Mystery

Pandemic Gas Mystery

Took a while to update, but here is some more data. Electricity stayed high until Spring 2021 and then dropped to roughly pre-pandemic levels. This is because I spent a lot of time in 2021 upgrading lighting. My house has a different type of fixture/bulb in every room making this a painful process but I'm almost 100% LED at this point which has made a difference. Gas on the other hand has got higher and stayed there and I should really replace some more windows and add some more insulation...

I really wish the utility companies made this data available through some useful API instead of needing to download the occasional CSV. I'd build a dashboard and obsess over energy usage far more.

Using the Azure Monitor REST API from Google Apps Script

By . Updated on

Average Server Response Time in Azure Metrics

This post describes how to get metrics (in this case average response time) from an Azure App Service into a Google Sheet. I’m doing this so I can go from the sheet to a Data Studio dashboard. I already have a report in Data Studio that pulls from Ads, Analytics and other sources. I’d rather spend hours adding Azure there than be forced to have one more tab open. You might have different reasons. Read on. 

  1. Create a Google Sheet and give it a memorable name. Rename the first sheet to AvgResponseTime and put ‘Date’ in A1 and ‘Average Response Time’ in B1.
  2. Create a script (Script editor from the Tools menu) and give that a good name as well.
  3. In the script editor pick Libraries from the Resources menu. Enter 1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF which is the Google OAuth library, pick the latest version and click Save.
  4. Select Project properties from the File menu and make a note of the Script ID.
  5. Log into your Azure Console and then go to https://resources.azure.com/. You are looking for a metricdefinitions node for the resource that you want to monitor. In my case it’s subscriptions / MyName Subscription / resourceGroups / providers / Microsoft.Web / sites / MySite / metricdefintions. Browse through this list to find the id of the metric you’re interested in. For me it’s AverageResponseTime. Finding this was the hardest part. Microsoft’s documentation for resourceUri is literally ‘The identifier of the resource.’ Why even bother Microsoft? Make a note of the id and remove the ‘metricDefinitions/AverageResponseTime’ from the end, because of course the ID isn’t quite right for some reason. Mine looks something like this: /subscriptions/mylongid/resourceGroups/mysomethingResourceGroup/providers/Microsoft.Web/sites/mysiteid
  6. Go back to the Azure Console and open Azure Active Directory. Select App registrations under Manage and create a New registration. Time to come up with another name. You probably want ‘Accounts in this organizational directory only’. The redirect URL is https://script.google.com/macros/d/SCRIPTID/usercallback - replace SCRIPTID with the Script ID you made a note of in step 4.
  7. Click the View API permissions button, then Add a permission and then pick Azure Service Management. I’m using Delegated permissions and the user_impersonation permission. Then click Grant admin consent for Default Directory.
  8. Go to Certificates & secrets (under manage) and create a new client secret. Make a careful note of it.
  9. Go to Authentication (under Manage), check Access tokens under Implicit grant and then click Save at the top of the page.
  10. Go to Overview and make a note of your Application (client) ID and Directory (tennant) ID.
  11. You are getting close! Go to the script editor (from step 2) and paste in the code at the bottom of this post. There are four variables to enter at the top of the script. ClientID and TennantID are from step 10. ClientSecret is from step 8. ResourceID is from step 5. Save the script.
  12. Reload the spreadsheet (back from step 1). You should get an Azure Monitor menu item. Choose Authorize from this menu. Google will ask you to authorize the script, do this for the Google account you’re using. Choose Authorize again, this time a sidebar will appear with a link. Follow the link and authorize against Azure (if you’re logged in this might just go directly to success). If you get authorization errors in the future run this step again. If that does help use Reset Settings and then try again.
  13. You should be ready to get data. Choose Fetch Data from the Azure Monitor menu. If this doesn’t work check through steps 1-12 carefully again!
  14. Last step - automate. Go back to the script editor. Choose Current project’s triggers from the Edit menu. Add a trigger (the small blue button hidden at the bottom right of the screen - not everything needs a floating action button Google!) to run fetchData daily at some reasonable time.
You should now have a daily record of average response time flowing to a Google sheet. This can easily be extended to support other metrics, and other time periods (you could get data by minute and run the script hourly for instance. See the metrics documentation for more ideas. I got this working for an App Service but it should be roughly the same flow for anything that supports metrics, you’ll just need to work on finding the right resourceUri / ID.

Email Alerts for new Referers in Google Analytics using Apps Script

By . Updated on

Referral Traffic in Google Analytics

It's useful to know when you have a new website referrer. Google Analytics is plagued with spam referral and you want to filter this out of reporting as quickly as possible to stop it from skewing your data. It's also helpful to be able to respond quickly to new referral traffic - maybe leave a comment or promote the new link on social media.

The script below will send you a daily email with links to any new referrers (this is GA3, there is a GA4 version later in this post).

Start a new apps script project in Google Drive and paste in the code. At the top enter the view ID that you want to monitor and the email address that should receive reports.

Choose Advanced Google Services from the Resources menu and switch on the Google Analytics API. Then click the Google API Console link and enable the Google Analytics API there as well.

Finally pick Current project's triggers from the Edit menu and trigger the main function daily at a convenient time.

This script saves known referrers in script properties. For a site with lots of traffic this may run out of space in which case you might need to switch this out and write known referrers to a sheet instead.

For Google Analytics 4 properties use the version of the script below. The setup process is the same, but you need the Google Analytics Data API instead of the Google Analytics API.

Get an email if your site stops being mobile friendly (no longer available)

By . Updated on

Google axed this tool today, so the script won't work any more. If you're looking for a replacement check out my Core Web Vitals script.

Get an email if your site stops being mobile friendly

Google just released an API for the mobile friendly test and so I've whipped up a script to send an alert if a web page violates their guidelines. This will run the test as often as you like and send you an email if it detects a problem. Alternatively if you're not mobile friendly it will keep emailing you until you fix any problems which might be a good motivational tool.

First start a new apps script project in drive and paste in the code below:

There are three variables you need to set, urlToMonitor is the full URL of the page to test, alertEmail is your email address (or whoever needs to be pestered) and runTestKey is the API key for the service. To get this go to the Google API Console, click Enable API, search for 'Google Search Console URL Testing Tools API' and click enable. Then click the Credentials option and generate a browser key.

Once you've configured the script choose 'Current project's triggers' from the Resources menu in apps script and set up a schedule for the mobileFriendlyMonitor() function.

Automate Google PageSpeed Insights and Core Web Vitals (CrUX) Logging with Apps Script

By . Updated on

Upload

Here's a quick script to automatically monitor your Google PageSpeed Insights desktop and mobile scores for a web page, together with core web vitals (LCP, INP and CLS):

You need a spreadsheet with a tab called results and an API key for PageSpeed Insights and the CrUX API (activate the APIs in the console and create an API key for them, the browser based / JavaScript option). Paste the code above into the script editor for the spreadsheet and add your API key and URLs to monitor. Then just choose triggers from the Resources menu and schedule the monitor function to run once per day.

The script will log the overall PageSpeed score out of 100 for the monitored page. It also logs 75th percentile origin level core web vitals (largest contentful paint (LCP, seconds), interaction to next paint (INP, seconds) and cumulative layout shift (CLS, percent)). If your origin does not have enough data the metric will be omitted. You can change from origin to page level web vitals if you have enough data, just change originLoadingExperience to loadingExperience for PageSpeed Insights and origin to url in the CrUX call.

The results are repeated for desktop and mobile, so your spreadsheet header should be Desktop PSI, Desktop LCP, Desktop INP, Desktop CLS, Mobile PSI, Mobile LCP, Mobile INP, Mobile CLS.

There are a lot of other values returned that you could choose to monitor as well. It would also be easy to extend this to monitor more URLs, or to send you an email if the score drops below a threshold.

Updated May 5, 2019 to use version 5 of the PageSpeed API.

Updated June 13, 2021 to include core web vitals.

Updated October 18, 2025 to use CrUX instead of PageSpeed for core web vitals (Google is removing web vitals from PageSpeed). CrUX might not have device level data for your origin and so the script will now report total aggregate data for both devices if this is the case. I ignore tablet, easy to add if you want it.