Automation is supposed to be about simplifying everyday tasks to give you more precious time doing the things you love. At XDA, we’ve shown you how you can use Tasker to secure your device, improve productivity, or make driving safer, all a part of our series called ‘Tasker Week.’
But the fun doesn’t end there. If you’ve been itching for some seriously awesome Tasker tasks (and are tired of the boring stuff like telling you how to reboot your phone or shake your phone to wake the display), then our new Tasker Pro series is for you.
We will be posting a series of highly advanced Tasker profiles that will show you just how powerful Tasker can be if you are willing to think outside of the box. Although we’ve done most of the hard work for you and you’re certainly free to import my profiles and use them as-is, I highly recommend you give learning how to use Tasker a shot if you want to be able to customize these tasks yourself. Over on our Tasker Tips & Tricks forums or on Reddit’s /r/Tasker subreddit, you can share and work with others on how to implement an idea you might have (as I have done many times).
This is Week 3 of Tasker pro. Last week, we showed you how you can use Tasker to track your mileage into an IRS compliant driving log. As promised, this week we will show you how to tag all new photos with the current calendar event.
Tasker Pro #3: Tagging Photos using your Google Calendar Events
Memories are a precious, yet transient part of our lives. Though we can only process, store, and remember a limited amount of long-term memories, thanks to modern technology we can digitally preserve our memories using cameras. Unfortunately, there’s always one major issue that we all have to face — how do we properly categorize our photos and videos? Using the technology available in cloud services such as Google Photos, we can automatically sort photos by date, location, and even by face (though that doesn’t always work out so well).
Properly tagging your digital photo files requires editing the image’s metadata which is stored as EXIF data. Most image editors will allow you to manually edit EXIF data so you can tag your own files with all the necessary information, but this can be quite cumbersome if you have a lot of photos and/or you forget to tag your photos soon after taking them. That’s why we can use Android’s native java functions combined with the power of Tasker in order to automatically tag new photos with a description matching the current Google Calendar event.
Requirements
Instructions
As this script does not require any third-party plug-ins, we can delve right into making the profile. Here is an overview of the contexts and the tasks that you’ll be creating.
Your first step is to create a new profile named “New Photos” with an Application context. Select the camera app that you normally use to take photos and back out. Now, create an entry task and leave it unnamed.
This entry task, as shown above, will only have a single action. Variables –> Variable Set. Name: %Start to %TIMES. What this will do is save the current time-stamp (in seconds since the epoch, as this is a format that’s easy to manipulate with Tasker.) We will use this in our main task below to only write to newly created photo files. Exit out of the entry task.
Create an exit task (you can add one by long-pressing on the entry task and then clicking “Add Exit Task”) and name it “Write Description“. Here are the actions in order:
- App –> Test App. Type: Calendar Title. Data: %Start. Store result in: %title. This will pull the title(s) of the current calendar event(s) and store it in a variable. Tasker doesn’t allow you to pick which calendar to pull from, but we’ll control for that below.
- App –> Test App. Type: Calendar Calendar. Data: %Start. Store result in: %calendar. Get the calendar name(s) of any ongoing event(s). We will use this to only events from calendars we care about.
- Task –> If. If %title1 is Set AND %calendar1 ~ YOURGOOGLECALENDAR
- Code –> Run Shell. The command will be: ls /sdcard/DCIM/Camera. Store output in %file. This will pull a list of files in your camera directory. Change the directory if you use a non-stock app.
- Variables –> Variable Split. Name: %file. Split the file array into individual file variables.
- Variables –> Array Pop. Variable: %file. Position: 999. To var: %photo. Label: CHECK NEXT PHOTO. Get the latest photo (assuming your photos are already sorted by time, which they should be unless you manually changed the output filenames.)
- File –> Test File. Type: Modified. Data: /sdcard/DCIM/Camera/%photo. Store result in: %timetaken. Determine when the photo was created/edited and store that timestamp in a variable (in seconds since the epoch).
- Task –> If. If %Start < %timetaken. Compare the timestamp of when you began taking photos to any photos you just took.
- Code –> Java Function. Class or Object: ExifInterface. Function: new {ExifInterface} (String). Param (String): /storage/emulated/0/DCIM/Camera/%photo. Return: exif. Initialize a new exif interface object with the data from the photo.
- Code –> Java Function. Class or Object: exif. Function: setAttribute {} (String, String). Param: UserComment. Param: %title1. Set the user comment exif attribute to the current event title.
- Code –> Java Function. Class or Object: exif. Function: saveAttributes {} (). Save the edited exif description to the image file.
- Task –> Else.
- Task –> Stop. If the starting timestamp is greater than the current image file’s timestamp, end the task as we’ve reached an older image.
- Task –> GOTO. Type: Action Label. Label: CHECK NEXT PHOTO. Look back to check the next photo in the array.
- Task –> End If.
- Code –> Java Object. Mode: Delete. Name: UserComment.
- Code –> Java Object. Mode: Delete. Name: exif. These two actions free up RAM by deleting initialized Java objects in Tasker.
That’s it! Here’s a screenshot of the Task in its entirety:
And voila! If you are able to follow along this, then congratulations, you’re pretty much a master of Tasker! Confused on a step and just want to import the script and get on with your life? I can’t blame you, this one took myself a lot of thinking to get it down right.
If you want to import this profile, you can download it from Android File Host here. In order to import the task, you need to first disable Beginner Mode in Tasker by going to the menu –> preferences. Under the UI tab, uncheck ‘Beginner Mode.’ Then back in the main Tasker menu, click on the ‘Tasks’ tab. Then long-press on the ‘Tasks’ tab and press ‘Import.’ Navigate to where you downloaded my .prf.xml file and select it to import it. Once you import it, you’re free to play around with it as you see fit. This script is ready to be used as-is, however, you should definitely change two things: first, change the app context to trigger based on whatever camera app you actually use (if you use Google Camera, then no need to change it), and secondly change the calendar context to fire only on the calendars you want it to monitor.
Next week for Tasker Pro I will show you how to copy a two-factory authentication code from text messages so you don’t have to leave your current app. Save and categorize your most precious moments!
What would you like to see me make with Tasker? Let us know below and we might feature your idea in a future article!
0 comments:
Post a Comment