sindresorhus / wallpaper

Manage the desktop wallpaper
MIT License
1.05k stars 91 forks source link

set wallpaper doesn't work #23

Closed SevenOutman closed 6 years ago

SevenOutman commented 7 years ago

My script looks like this:

wallpaper.set(fullImagePath).then(() => {
  console.log('Set as wallpaper')
  wallpaper.get().then(imagePath => {
       console.log(`Current wallpaper: ${imagePath}`)
  })
})

which is run by crontab on Ubuntu 16.04 (with GNOME). The wallpaper doesn't change, and the logged imagePath does not equal fullImagePath. The output was like:

Image already downloaded at: /home/doma/scripts/bing-wallpaper-script/downloads/20170605.jpg
Set as wallpaper
Current wallpaper: /usr/share/backgrounds/warty-final-ubuntu.png

However when I run this script manually (not invoke by crontab), it works fine.

fa7ad commented 7 years ago

Could it be a problem with the user being used to execute the commands from crontab?

SevenOutman commented 7 years ago

@fa7ad Not really. I run crontab as the same user with that when I run my script manually. By the way, if set method fails on user permission, I think its Promise should have been rejected.

fa7ad commented 7 years ago

FWIW, can you try running the script through a nodejs script?

setInterval(() => {
  wallpaper.set(...)
}, 60000)

and keeping that running (like a daemon)

SevenOutman commented 7 years ago

@fa7ad Thanks, your approach may work. However, it's not actually my final goal to change wallpaper at an interval. I was trying to run my script upon system wakeup (Ubuntu has hooks for that), but it didn't work. So I tried running my script with crontab, but it didn't work as well. I guess these 2 scenarios have a same cause, so I only mentioned the crontab scenario in this issue for easier understanding.

fa7ad commented 7 years ago

@SevenOutman If your goal is to run at startup, try creating a .desktop file at ~/.config/autostrart or using a systemd service (just set the user and group options)

SevenOutman commented 7 years ago

@fa7ad Thanks for your advice. But I want to run my script at wakeup, not startup.

fa7ad commented 7 years ago

@SevenOutman sorry, missed that. well, good luck