Random wallpaper
Moderator: Martin
Random wallpaper
Hello,
I create this flow to change wallpaper randomly, I think there is a simpler and more optimized way to do it but I don't know how.
What do you think ?
Thanks
I create this flow to change wallpaper randomly, I think there is a simpler and more optimized way to do it but I don't know how.
What do you think ?
Thanks
- Attachments
-
- Screenshot_20181030-211106.jpg (565.23 KiB) Viewed 25197 times
Re: Random wallpaper
Hi,
maybe you could do the following.
Start with your trigger.
Connect it to a Script action:
Then use your action (Set Live Wallpaper), but use {random_wallpaper} as value for the Live Wallpaper.
maybe you could do the following.
Start with your trigger.
Connect it to a Script action:
Code: Select all
wallpapers = newList("Name of wallpaper 1.", "Name of wallpaper 2.", "Name of wallpaper 3.", ...);
random_wallpaper = getRandomElement(wallpapers);
Last edited by Helios on 31 Oct 2018 11:48, edited 1 time in total.
Re: Random wallpaper
I try with one wallpaper but it doesn't work
I don't know if it's the right name of the wallpaper or if I did something wrong with the script.
31.10.2018 10:20:22.333 [Fond d'écran jour copy] Error:
ch.gridvision.ppam.androidautomagic.simplelang.a.d: Could not evaluate expression 'wallpapers = newList("Dans la lune",)
random_wallpaper = getRandomElement(wallpapers)' due to errors: [expression expected[36], ';' expected[38]]
I don't know if it's the right name of the wallpaper or if I did something wrong with the script.
31.10.2018 10:20:22.333 [Fond d'écran jour copy] Error:
ch.gridvision.ppam.androidautomagic.simplelang.a.d: Could not evaluate expression 'wallpapers = newList("Dans la lune",)
random_wallpaper = getRandomElement(wallpapers)' due to errors: [expression expected[36], ';' expected[38]]
Re: Random wallpaper
The error is at the missing semicolon (;) at the end of the first line. And also additional comma for one element only. You should put semicolon and also remove the comma
Helios just give you example, so semicolon is missing from the script. The proper one should be
Make it as a habit to always end the line with semicolon (unless for certain if() else situation). And because you have 15, it will better to separate each wallpaper into new line for better view/reading. For example
The random method you get here is truly random. In 15 execution, it is possible that some wallpaper haven't been appear once and there are some appear twice. If you need random, but each wallpaper must appear once in every 15 execution; then you should create the list in glovar, example global_wallpapers. Then store the execution count in another glovar. If executed 15 times, shuffle it and reset the count to 0.
To create the glovar, you can add it manually and use list type. Or you can just type in script for one time creation.
Execute this once, it will create your glovar and count. Then delete the script and use this script for the loop.
First we get the random wallpaper from the shuffled glovar (first 15 execution is not shuffled yet) based on the current count. Increment the count, so next time it gets the next wallpaper. Check if the count is 15 already (already execute 15 times). If yes, shuffle it again and set the count to 0, so it restart to retrieve from the first random element.
In total, you need only one trigger, one script and one set live wallpaper (and 2 glovar). Much more efficient flow
About the trigger, it seems you use some other plugin to do it. If your trigger is notification on statusbar, Automagic already have that trigger, try to find it in the trigger list.
Code: Select all
wallpapers = newList("Dans la lune",)
random_wallpaper = getRandomElement(wallpapers)
Code: Select all
wallpapers = newList("Dans la lune");
random_wallpaper = getRandomElement(wallpapers);
Code: Select all
wallpapers = newList(
"Wallpaper1",
"Wallpaper2",
"Wallpaper3",
"Wallpaper4",
"Wallpaper5");
random_wallpaper = getRandomElement(wallpapers);
To create the glovar, you can add it manually and use list type. Or you can just type in script for one time creation.
Code: Select all
global_wallpapers = newList(
"Wallpaper1",
"Wallpaper2",
"Wallpaper3",
"Wallpaper4",
"Wallpaper5");
global_wallpapers_count = 0;
Code: Select all
random_wallpaper = global_wallpapers[global_wallpapers_count];
global_wallpapers_count = global_wallpapers_count + 1;
if(global_wallpapers_count == 15)
{
shuffleList(global_wallpapers);
global_wallpapers_count = 0;
}
In total, you need only one trigger, one script and one set live wallpaper (and 2 glovar). Much more efficient flow
About the trigger, it seems you use some other plugin to do it. If your trigger is notification on statusbar, Automagic already have that trigger, try to find it in the trigger list.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Random wallpaper
Hi,
The script work but I don't understand how to create the glovar.
The trigger is good, I use it with other flow and IFTTT.
Thanks
The script work but I don't understand how to create the glovar.
The trigger is good, I use it with other flow and IFTTT.
Thanks
Re: Random wallpaper
You can swipe from left to open the hamburger menu (where you can access Automagic Settings) There is Global Variables, tap that. Click plus sign and add global_wallpapers, change the type from string to list. Add value and add each of your wallpaper name until finish. Then add another glovar global_wallpapers_count with value 0.
Or you can just simply add it in script just like here
After changing wallpaper1 to your wallpaper name, tap 3 dot menu at top right > execute. This will execute the script and create the glovar directly. After that, you can delete the script, as it is one-time-job only.
Or you can just simply add it in script just like here
Code: Select all
global_wallpapers = newList(
"Wallpaper1",
"Wallpaper2",
"Wallpaper3",
"Wallpaper4",
"Wallpaper5");
global_wallpapers_count = 0;
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Random wallpaper
The value doesn't change after an execution. I don't know where I'm wrong.
Re: Random wallpaper
Which value? The global_wallpapers? That one only change after 15 executions, not every execution. So you have random list, but every wallpaper should appear at least once in 15 executions.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Re: Random wallpaper
It's doesn't work, sometimes I have the same wallpaper twice.
Re: Random wallpaper
For each 15 execution it will be different. However, after 15, the list got randomized. It is possible at 15th, you got wallpaper A as the last. Then at the next randomize, A become the first element, hence it seems you got the same wallpaper again. if it is necessary, you can check for the previous wallpaper. If it is the same with the next one, you can shuffle it again, or just use the next element.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.