Random wallpaper

General discussions about Automagic and automation in general

Moderator: Martin

Vicdilou
Posts: 10
Joined: 26 Sep 2018 22:29

Random wallpaper

Post by Vicdilou » 30 Oct 2018 20:15

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
Attachments
Screenshot_20181030-211106.jpg
Screenshot_20181030-211106.jpg (565.23 KiB) Viewed 24743 times

User avatar
Helios
Posts: 17
Joined: 22 Oct 2018 09:41

Re: Random wallpaper

Post by Helios » 30 Oct 2018 22:32

Hi,

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);
Then use your action (Set Live Wallpaper), but use {random_wallpaper} as value for the Live Wallpaper.
Last edited by Helios on 31 Oct 2018 11:48, edited 1 time in total.

Vicdilou
Posts: 10
Joined: 26 Sep 2018 22:29

Re: Random wallpaper

Post by Vicdilou » 31 Oct 2018 09:21

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]]

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Random wallpaper

Post by Desmanto » 31 Oct 2018 11:00

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

Code: Select all

wallpapers = newList("Dans la lune",)
random_wallpaper = getRandomElement(wallpapers)
Helios just give you example, so semicolon is missing from the script. The proper one should be

Code: Select all

wallpapers = newList("Dans la lune");
random_wallpaper = getRandomElement(wallpapers);
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

Code: Select all

wallpapers = newList(
"Wallpaper1",
"Wallpaper2",
"Wallpaper3",
"Wallpaper4",
"Wallpaper5");
random_wallpaper = getRandomElement(wallpapers);
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.

Code: Select all

global_wallpapers = newList(
"Wallpaper1",
"Wallpaper2",
"Wallpaper3",
"Wallpaper4",
"Wallpaper5");
global_wallpapers_count = 0;
Execute this once, it will create your glovar and count. Then delete the script and use this script for the loop.

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;
}
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.
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.

Vicdilou
Posts: 10
Joined: 26 Sep 2018 22:29

Re: Random wallpaper

Post by Vicdilou » 31 Oct 2018 12:53

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

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Random wallpaper

Post by Desmanto » 31 Oct 2018 18:30

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

Code: Select all

global_wallpapers = newList(
"Wallpaper1",
"Wallpaper2",
"Wallpaper3",
"Wallpaper4",
"Wallpaper5");
global_wallpapers_count = 0;
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.
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.

Vicdilou
Posts: 10
Joined: 26 Sep 2018 22:29

Re: Random wallpaper

Post by Vicdilou » 31 Oct 2018 19:10

The value doesn't change after an execution. I don't know where I'm wrong.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Random wallpaper

Post by Desmanto » 01 Nov 2018 15:06

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.

Vicdilou
Posts: 10
Joined: 26 Sep 2018 22:29

Re: Random wallpaper

Post by Vicdilou » 03 Nov 2018 06:45

It's doesn't work, sometimes I have the same wallpaper twice.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Random wallpaper

Post by Desmanto » 03 Nov 2018 18:30

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.

Post Reply