An Almost Anonymous Blog

Random Daily Wallpaper With Tasker

I have a hard time picking and choosing a wallpaper for my phone. I'm sure I'm not the only one with that problem. There are apps out there that give you daily wallpapers from various sources (I think Unsplash is one of them), but I like choosing my own rather than put blind faith into a random generator that I'll get something I will like.

So I have a folder full of wallpapers that I have chosen over the last little while. Most of the time they sit on my phone, doing nothing. Well...I decided I'd do something about it. Enter Tasker, a robust automation app that I don't use so much anymore, but is very good at what it does. Which is almost everything.

Anyway, here's the task I set up to run, every day at 00:00.

A1: List Files [
         Directory: DCIM/Wallpaper
         Sort Select: Alphabetic
         Variable Array: %wallpaper
         Use Global Namespace: On ]

    A2: Variable Set [
         Name: %wallpapermax
         To: %wallpaper(#) ]

    A3: Variable Randomize [
         Name: %num
         Min: 1
         Max: %wallpapermax ]

    A4: Variable Set [
         Name: %index
         To: %LastNum(#?%num)
         Structure Output (JSON, etc): On ]

    A5: Goto [
         Type: Action Number
         Number: 4 ]
        If  [ %index > 0 & %qtime < 60 ]

    A6: Array Pop [
         Variable Array: %LastNum
         Position: 3 ]
        If  [ %LastNum(#) eq 3 ]

    A7: Array Push [
         Variable Array: %LastNum
         Position: 1
         Value: %num ]

    A8: Variable Set [
         Name: %newwall
         To: %LastNum(1)
         Structure Output (JSON, etc): On ]

    <Set the wallpaper>
    A9: Set Wallpaper [
         Type: Lockscreen
         Image: %wallpaper(%newwall) ]

The short version: it lists the number of files in the Wallpaper folder, and then generates a random number between 1 and that number of files. It then picks a wallpaper that corresponds to whatever number (so if cats.jpg is wallpaper #5, and that's the number chosen, then I get cats.jpg as my wallpaper).

However I've done random number generation of this sort before and have found that it's not always truly "random". I thought that it would be best to check to see if the number was the same as yesterday's number, and if so, pick a new number. I'm not the best in figuring this stuff out on my own so I borrowed heavily from the Tasker subreddit (/u/Ratchet_Guy is an amazing Tasker guru). I would never have thought of using an array this way, or known exactly what kind of syntax to use.

The slightly longer explanation of what's going on:

Neat stuff!

Reply by email

Or if you prefer, find me on Mastodon.

Edit: Forgot to put in the link to Tasker (:

#tech