Skip to content
This repository has been archived by the owner on Feb 7, 2025. It is now read-only.

Works from terminal, but no image from cron job #123

Open
ihtruelsen opened this issue Nov 17, 2021 · 2 comments
Open

Works from terminal, but no image from cron job #123

ihtruelsen opened this issue Nov 17, 2021 · 2 comments

Comments

@ihtruelsen
Copy link

I can run it from terminal with the following output:

ian@ian-MS-7C84:~$ /home/ian/.local/bin/himawaripy --auto-offset
himawaripy 2.2.0
Updating...
Latest version: 2021/11/17 22:20:00 GMT.
Detected offset: UTC-08:00
Offset version: 2021/11/17 04:20:00 GMT.
Downloading tiles...
Downloading tiles: 1/16 completed...
Downloading tiles: 2/16 completed...
Downloading tiles: 3/16 completed...
Downloading tiles: 4/16 completed...
Downloading tiles: 5/16 completed...
Downloading tiles: 6/16 completed...
Downloading tiles: 7/16 completed...
Downloading tiles: 8/16 completed...
Downloading tiles: 9/16 completed...
Downloading tiles: 10/16 completed...
Downloading tiles: 11/16 completed...
Downloading tiles: 12/16 completed...
Downloading tiles: 13/16 completed...
Downloading tiles: 14/16 completed...
Downloading tiles: 15/16 completed...
Downloading tiles: completed.
Saving to '/home/ian/.cache/himawaripy/himawari-20211117T042000.png'...
No such key “draw-background”
No such key “draw-background”
Exception in thread himawaripy-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 973, in _bootstrap_inner
self.run()
File "/usr/lib/python3.9/threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "/home/ian/.local/lib/python3.9/site-packages/himawaripy/main.py", line 214, in thread_main
r = set_background(output_file)
File "/home/ian/.local/lib/python3.9/site-packages/himawaripy/utils.py", line 36, in set_background
assert os.system('bash -c "gsettings set org.gnome.desktop.background draw-background true"') == 0
AssertionError

This produces an image as expected.

This is my crontab line:
5 * * * * /home/ian/.local/bin/himawaripy --auto-offset >> /home/ian/log/cron.log 2>&1

This is the output of my cron.log:

himawaripy 2.2.0
Updating...
Latest version: 2021/11/17 21:40:00 GMT.
Detected offset: UTC-08:00
Offset version: 2021/11/17 03:40:00 GMT.
Downloading tiles...
Downloading tiles: 1/16 completed...
Downloading tiles: 2/16 completed...
Downloading tiles: 3/16 completed...
Downloading tiles: 4/16 completed...
Downloading tiles: 5/16 completed...
Downloading tiles: 6/16 completed...
Downloading tiles: 7/16 completed...
Downloading tiles: 8/16 completed...
Downloading tiles: 9/16 completed...
Downloading tiles: 10/16 completed...
Downloading tiles: 11/16 completed...
Downloading tiles: 12/16 completed...
Downloading tiles: 13/16 completed...
Downloading tiles: 14/16 completed...
Downloading tiles: 15/16 completed...
Downloading tiles: completed.
Saving to '/home/ian/.cache/himawaripy/himawari-20211117T034000.png'...
Could NOT retrieve env. var. DESKTOP_SESSION
Could NOT retrieve env. var. KDE_FULL_SESSION
Could NOT retrieve env. var. GNOME_DESKTOP_SESSION_ID
Could NOT retrieve env. var. XDG_CURRENT_DESKTOP
Fetched env. var. DBUS_SESSION_BUS_ADDRESS as unix:path=/run/user/1000/bus
Could NOT retrieve env. var. DISPLAY
Could NOT retrieve env. var. DESKTOP_SESSION
Could NOT retrieve env. var. KDE_FULL_SESSION
Could NOT retrieve env. var. GNOME_DESKTOP_SESSION_ID
Could NOT retrieve env. var. XDG_CURRENT_DESKTOP

And the background is black.

I am running Ubuntu 21.10 with gnome-shell version 40.5

@skyywj
Copy link

skyywj commented Feb 1, 2022 via email

@zzbajie
Copy link

zzbajie commented Sep 13, 2022

Ubuntu22.04 GNOME

sudo nano /home/xxx/himawaripy.sh
crontab -e
*/10 * * * * /home/xxx/himawaripy.sh

#!/bin/bash

${HOME}/.local/bin/himawaripy --auto-offset --dont-change
#--dont-change 只下载不修改壁纸

sleep 15

Wallpaper's directory.

dir="${HOME}/.cache/himawaripy/"

Environment variable

PID=$(pgrep gnome-session|head -n1)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)

Random wallpaper.

wallpaper=find "${dir}" -type f | shuf -n1

Change wallpaper.

/usr/bin/gsettings set org.gnome.desktop.background picture-options "scaled"
/usr/bin/gsettings set org.gnome.desktop.background picture-uri "file://${wallpaper}"
`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants