Friday, November 18, 2022

Tasker: Auto Downloading a Random Pic From A Google Photos Album

I wanted to dress up my Tasker based Focus Mode by adding a picture on the Focus Overlay scene. To make things more interesting, I wanted to it to be a random pic of my wife that would update on a regular basis. After all, she's the one I'm usually trying to focus for.

Here's what the finished product ended up looking like:

Here's how I got this to work:

1. I Created a Google Photos live album. This is a slick feature offered by Google Photos that causes photos to be auto-added to an album every time the selected face is detected in an image.

2. I figured out this album's Album ID using the Google Photos API's try this method feature.

3. I headed over to console.developers.google.com and created a new project and enabled the Google Photos API on it. This project is needed so I can authenticate with the Google Photos API and access my private photos in a secure way.

4. While on console.developers.google.com I added a new set of credentials. I chose OAuth client id for the type of credentials and selected Web Application under application type. Finally, I added https://tasker.joaoapps.com/auth.html to the Authorized Redirect URIs as noted in the Tasker Documentation.

I saved the Client ID and Client secret shown on the credentials page as I would be using them later on in the process.

5. Switching into Tasker, I created a general purpose task that grabs a random photo from a Google Photos Album. You can grab this task from TaskerNet. I fell back on my usual strategy of using Javacriplets to set up calls to, and process the response from, an API. In this case I'm making two web calls: the first to the API to get the details of the first 100 photos in the album identified by %par1. I'm then randomly picking one the mediaItems, and downloading it to the filename provided in %par2.

6. I created a Grab Random Wife Picture task which calls the task in step (5) with the album ID and file name of my choice.

7. I created a time based profile that runs on the hour, throughout the day, and calls the task in step (6).

8. Finally, I updated the Focus Overlay, swapping out the text box that read 'Focus' with an image element. The image element uses the path to the downloaded file, which is updated hourly.

Whenever I launch focus mode it shows me the latest image that has been downloaded. And most importantly, it makes me smile.

No comments:

Post a Comment