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:
- As mentioned, the number of files in the wallpaper folder is determined at the start of the task, and a random number is generated between 1 and that maximum number (
%wallpapermax%
). For example, a number between 1 and 12. - There is a check to see if the random number exists in our
%LastNum()
array - if it is, the task loops back to the beginning; if not, it continues (%qtime < 60
is a timeout task so there's no getting stuck in a time loop). - The array is basically made up of three numbers, and the third is removed from the end, and the new random number is placed at the beginning.
- More stuff happens and then the lock screen wallpaper is set to the file corresponding to the random number.
Neat stuff!
Reply by email
Or if you prefer, find me on Mastodon.
Edit: Forgot to put in the link to Tasker (: