You are not logged in.

#1 2017-01-12 14:48:18

ragamatrix
Member
Registered: 2015-10-04
Posts: 427

Help to display differents pictures every 2 hours

Hello and Happy new year to everyone !

I made differents high-resolution pictures of the earth and I'd like to display them each 2hours.
I tried to launch a script in a crontab to display these pictures but I did something wrong and it's doing nothing.
I begin 9 scripts one for example this one for 8 o'clock (the second one for 10, third for 12 etc...):

#!/bin/bash
feh --bg-scale ~/.xplanet/images/Earth_HD/earth-hd/HPH-MAPS/easteeuropa-1920-8h.jpg 
done

I'm really bad with maths and codes, I only got ideas and need a little help to realize this, help will be much apreciated.
In advance thanks wink

Offline

#2 2017-01-12 14:56:13

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Help to display differents pictures every 2 hours

Simple one-liner that shows a random selection of images:

while true ; do feh --bg-scale --randomize "$HOME"/.xplanet/images/Earth_HD/earth-hd ; sleep 7200 ; done

A bit more is needed to show the images in order:

[non-working code redacted]

Untested and I'm sure there is a much better way of doing that big_smile

EDIT: to clarify, simply call those from ~/.config/openbox/autostart

No need for cronjobs or anything wink

EDIT2: ha! the second one doesn't work at all lol

Sorry OP, give me a minute...

Last edited by Head_on_a_Stick (2017-01-12 15:13:43)

Offline

#3 2017-01-12 15:15:01

ragamatrix
Member
Registered: 2015-10-04
Posts: 427

Re: Help to display differents pictures every 2 hours

thank you ! I'll try that, and yes the pics must be displayed in order of "time" each 2hrs.

Offline

#4 2017-01-12 15:16:09

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Help to display differents pictures every 2 hours

Working, tested version:

#!/bin/sh
for i in "$HOME"/.xplanet/images/Earth_HD/earth-hd/* ; do
    feh --bg-scale "$i" 2>/dev/null && sleep 7200 || continue
done

smile

Last edited by Head_on_a_Stick (2017-01-12 15:17:07)

Offline

#5 2017-01-12 15:16:09

ragamatrix
Member
Registered: 2015-10-04
Posts: 427

Re: Help to display differents pictures every 2 hours

oops I miss the post or something ... I can wait a little wink
EDIT
The script "knows" what time it is for launching the picture of the moment of the day... (sorry for my english)?
For example if it's 3pm it will launch the 4pm one ?
big thanks !

Last edited by ragamatrix (2017-01-12 15:31:08)

Offline

#6 2017-01-12 15:19:59

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Help to display differents pictures every 2 hours

I tweaked the script a bit (forgot to full-quote the variables, ahem), to alter the interval change the "sleep" command, it measures in seconds wink

Offline

#7 2017-01-12 16:48:22

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Help to display differents pictures every 2 hours

ragamatrix wrote:

The script "knows" what time it is for launching the picture of the moment of the day... (sorry for my english)?
For example if it's 3pm it will launch the 4pm one ?

Sorry, I missed this.

Well, the lines I posted will simply go through all of the files in the ~/.xplanet/images/Earth_HD/earth-hd/ folder and attempt to set them as a wallpaper then wait 7200 seconds (`sleep 7200`) and go to the next file in the list and try again.

To have specific wallpapers show at particular times would require a more complicated script.

Last edited by Head_on_a_Stick (2017-01-12 16:50:51)

Offline

#8 2017-01-12 17:10:28

ragamatrix
Member
Registered: 2015-10-04
Posts: 427

Re: Help to display differents pictures every 2 hours

No problem, thanks for these clear explanations, I'll have to search how to do what I would... for example if it's 9am I'd like that the script displays the 10am picture and continues with 12am, 14pm,16pm,18pm,20pm... Thank you for your help.

Offline

#9 2017-01-12 19:17:37

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Help to display differents pictures every 2 hours

OK, so with a systemd .timer:

First, create the directories needed to run --user units:

mkdir -p ~/.config/systemd/user

Then create ~/.config/systemd/user/wallchanger.timer (as your normal user):

[Unit]
Description=Change wallpaper at set times.

[Timer]
OnCalendar=*-*-* 2,4,6,8,10,12,14,16,18,20,22:00:00
Persistent=true

[Install]
WantedBy=timers.target

With the matching ~/.config/systemd/user/wallchanger.service

[Unit]
Description=Change wallpaper at set times.

[Service]
Type=oneshot
Environment=DISPLAY=:0
ExecStart=/bin/sh -c "for i in $(/bin/date | /usr/bin/awk -F '[ :]' '{print $4}') ; do /usr/bin/feh --bg-scale $HOME/.xplanet/images/Earth_HD/earth-hd/$i.png 2>/dev/null ; done"

This requires that the wallpaper pictures be named 10.jpg, 12.jpg, 14.jpg, etc.

Enable the .timer (to start at the next and sunsequent boots) with:

systemctl --user enable wallchanger.timer

Start the .timer immediately with:

systemctl --user start wallchanger.timer

Check the status with:

systemctl --user list-timers

smile

EDIT2: changed "Type=" from "oneshot" to "simple", maybe more changes to come...

I'm awful, I know hmm

Last edited by Head_on_a_Stick (2017-01-12 20:41:15)

Offline

#10 2017-01-12 20:42:57

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Help to display differents pictures every 2 hours

The final working version is posted above, no need for separate scripts, just ~/.config/systemd/user/wallchanger.{service,timer}

Offline

#11 2017-01-13 07:44:18

ragamatrix
Member
Registered: 2015-10-04
Posts: 427

Re: Help to display differents pictures every 2 hours

morning'
Just launched the 2 scripts to test, waiting for 10:00 to know if it's working, then I'll post an archive with the pictures to share it for everybody. Thanks again Head_on_Stick !

Offline

#12 2017-01-13 09:04:57

ragamatrix
Member
Registered: 2015-10-04
Posts: 427

Re: Help to display differents pictures every 2 hours

don't know why, nothing happened:

raphix@debian:~$ systemctl --user list-timers
NEXT                         LEFT          LAST                         PASSED       UNIT              ACTIVATES
ven 2017-01-13 12:00:00 +02  1h 56min left ven 2017-01-13 10:00:46 +02  2min 38s ago wallchanger.timer wallchanger.service

1 timers listed.
Pass --all to see loaded but inactive timers, too.
raphix@debian:~$ 

Offline

#13 2017-01-13 11:32:50

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,697

Re: Help to display differents pictures every 2 hours

ragamatrix wrote:

don't know why, nothing happened:

Maybe I'm wrong...

the service would have to be supplemented?

HoaS wrote:

With the matching ~/.config/systemd/user/wallchanger.service

[Unit]
Description=Change wallpaper at set times.

[Service]
Type=oneshot
Environment=DISPLAY=:0
ExecStart=/bin/sh -c "for i in $(/bin/date | /usr/bin/awk -F '[ :]' '{print $4}') ; do /usr/bin/feh --bg-scale $HOME/.xplanet/images/Earth_HD/earth-hd/$i.png 2>/dev/null ; done"

[Install]                   <---
WantedBy=graphical.target   <---

Offline

#14 2017-01-13 14:18:19

ragamatrix
Member
Registered: 2015-10-04
Posts: 427

Re: Help to display differents pictures every 2 hours

I've founded a script which I made, modified a little with the hi-res earth maps but xplanet uses a lot of cpu to make them every 10 minutes with a crontab. For the moment I use this one waiting for a lighter solution with your systemd scripts great ideas.
I found the render really nice !
1484317084.png

Offline

#15 2017-01-13 17:25:56

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,697

Re: Help to display differents pictures every 2 hours

^ at 2 pm I had not yet installed feh ...  :8
at 16.00 clock I was not at home and the computer slept ...
now at 18.00 systemd changes me the background image!  big_smile

2017-01-13-18-12-26_scrot.th.png

Wow HoaS, it works as you thought.

My service:

[Unit]
Description=Change wallpaper at set times.

[Service]
Type=simple
Environment=DISPLAY=:0
ExecStart=/bin/sh -c "for i in $(/bin/date | /usr/bin/awk -F '[ :]' '{print $4}') ; do /usr/bin/feh --bg-scale $HOME/tmp/$i.png 2>/dev/null ; done"

[Install]
WantedBy=graphical.target

at 20.00 clock your wallpaper - ragamatrix - would be the turn. wink

I'm curious.

Offline

#16 2017-01-13 18:39:56

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Help to display differents pictures every 2 hours

Thanks for testing unklar smile

Do you actually need that [Install] section in wallchanger.service?

The .timer works fine in my BunsenLabs system without that section and that stanza would only be parsed if `systemctl --user {enable,start} wallchanger.service` was used and that is not the command that should be used.

These commands should be used instead:

systemctl --user start wallchanger.timer # starts .timer immediately
systemctl --user enable wallchanger.timer # starts .timer automatically from the next boot

@Ragamatrix: I'm happy to troubleshoot this if you are smile

Can you confirm how exactly you have set things up?

What is the output of:

systemctl --user list-timers
systemctl --user status wallchanger.{timer,service}

Also, does my ExecStart command actually work on your system?

Try running it from a terminal:

/bin/sh -c "for i in $(/bin/date | /usr/bin/awk -F '[ :]' '{print $4}') ; do /usr/bin/feh --bg-scale $HOME/tmp/$i.png 2>/dev/null ; done"

Check if the full paths to the commands are correct with `which {sh,date,awk,feh}` and change if needed.

Last edited by Head_on_a_Stick (2017-01-13 19:01:50)

Offline

#17 2017-01-13 19:31:30

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,697

Re: Help to display differents pictures every 2 hours

At first, the background image also changes at 8 pm   smile
2017-01-13-20-03-36_scrot.th.png

HoaS wrote:

Do you actually need that [Install] section in wallchanger.service?

$ systemctl status --user wallchanger.service
● wallchanger.service - Change wallpaper at set times.
   Loaded: loaded (/home/unklar/.config/systemd/user/wallchanger.service; disabled)
   Active: inactive (dead) since Fr 2017-01-13 20:00:42 CET; 18min ago
  Process: 14840 ExecStart=/bin/sh -c for i in $(/bin/date | /usr/bin/awk -F '[ :]' '{print $4}') ; do /usr/bin/feh --bg-scale $HOME/tmp/$i.png 2>/dev/null ; done (code=exited, status=0/SUCCESS)
 Main PID: 14840 (code=exited, status=0/SUCCESS)

Without the [Install] section I have not tried yet, because it did not work at @ragamatrix ...

$ systemctl status --user wallchanger.timer
● wallchanger.timer - Change wallpaper at set times.
   Loaded: loaded (/home/unklar/.config/systemd/user/wallchanger.timer; enabled)
   Active: active (waiting) since Fr 2017-01-13 13:00:10 CET; 7h ago

Last edited by unklar (2017-01-13 19:35:46)

Offline

#18 2017-01-13 21:17:59

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,697

Re: Help to display differents pictures every 2 hours

^ ok HoaS, it is 22.00 clock and he makes the change also without the [Install] statement. big_smile
2017-01-13-22-02-22_scrot.th.png
But I did not understand it yet.

systemctl status --user wallchanger.service
● wallchanger.service - Change wallpaper at set times.
   Loaded: loaded (/home/unklar/.config/systemd/user/wallchanger.service; static)
   Active: inactive (dead) since Fr 2017-01-13 22:00:54 CET; 2min 54s ago
  Process: 2743 ExecStart=/bin/sh -c for i in $(/bin/date | /usr/bin/awk -F '[ :]' '{print $4}') ; do /usr/bin/feh --bg-scale $HOME/tmp/$i.png 2>/dev/null ; done (code=exited, status=0/SUCCESS)
 Main PID: 2743 (code=exited, status=0/SUCCESS)
systemctl status --user wallchanger.timer
● wallchanger.timer - Change wallpaper at set times.
   Loaded: loaded (/home/unklar/.config/systemd/user/wallchanger.timer; enabled)
   Active: active (waiting) since Fr 2017-01-13 21:10:23 CET; 53min ago
[Unit]
Description=Change wallpaper at set times.

[Service]
Type=simple
Environment=DISPLAY=:0
ExecStart=/bin/sh -c "for i in $(/bin/date | /usr/bin/awk -F '[ :]' '{print $4}') ; do /usr/bin/feh --bg-scale $HOME/tmp/$i.png 2>/dev/null ; done"

Difference:
The service is now marked as * static * = * disabled *.

Last edited by unklar (2017-01-14 09:32:44)

Offline

#19 2017-01-13 22:47:26

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Help to display differents pictures every 2 hours

Thanks again unklar, the "static" type is correct for wallchanger.service — we don't want to enable that .service directly anyway.

Last edited by Head_on_a_Stick (2017-01-13 22:48:08)

Offline

#20 2017-01-14 09:29:31

unklar
Back to the roots 1.9
From: #! BL
Registered: 2015-10-31
Posts: 2,697

Re: Help to display differents pictures every 2 hours

^ You are welcome.  smile

Offline

Board footer

Powered by FluxBB