[Solved]: How can I change desktop image realtime from bash?

Please post suggestions for improvement of Cinnamon on:
https://github.com/linuxmint/Cinnamon
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
mikecolley
Level 3
Level 3
Posts: 118
Joined: Fri May 20, 2011 5:41 am

[Solved]: How can I change desktop image realtime from bash?

Post by mikecolley »

Hi All:

LM17 Cinnamon USB live session with casper-rw persistent partition here.

How can I change the desktop image in realtime to a different (new) image? I'm not looking for a special program to do this, I would just like to be able to put the most recent webcam ( 2014............jpg ) picture as the desktop image and do this from a script file in bash in the background and have it take effect immediately. If it is complicated, I don't really need to do it, but if it is a simple command, then I would like to do it.

Another question #2 less important, would it be easy to take the live output of the laptop camera and use it as the desktop image? and be stretched?

Another question #3 less important, how can I take the most recent wunderground local radar image and make it the desktop image? and be stretched?

Thanks All - Mike
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Kalyk
Level 5
Level 5
Posts: 769
Joined: Wed Mar 12, 2014 5:29 pm
Location: The Netherlands

Re: How can I change desktop image realtime from bash?

Post by Kalyk »

Search on this forum and found an example somewhere for Mate, which didn't work but gave a clue.
This way you can change the background from the command prompt

Code: Select all

cd ~/Pictures
gsettings set  org.cinnamon.desktop.background picture-uri 'file:///home/mintuser/Pictures/test.jpg'
cp dexxus_4714207610.jpg test.jpg
The first command gave test.jpg as the background, the cp made the background change on the fly.
So now you only have to get the image and try if you need to resize it.
Ok, this is of course also simple to try so I did that and the picture is made screen size by default.
Hope this helps :-)

Edit: the line which starts at gsettings ends with the quote after test.jpg !! Was wrong in my layout when I saw my answer.

And while I'm ED IT:
This gives some more info

Code: Select all

mintuser@LM17-64CinVM ~/Pictures $ gsettings list-recursively org.cinnamon.desktop.background
org.cinnamon.desktop.background picture-uri 'file:///home/mintuser/Pictures/test.jpg'
org.cinnamon.desktop.background color-shading-type 'solid'
org.cinnamon.desktop.background primary-color '#000000'
org.cinnamon.desktop.background picture-options 'zoom'
org.cinnamon.desktop.background picture-opacity 100
org.cinnamon.desktop.background secondary-color '#000000'
Add (Solved) to the topic-title of the first post when appropriate so others know they might find a solution here.
mikecolley
Level 3
Level 3
Posts: 118
Joined: Fri May 20, 2011 5:41 am

Re: How can I change desktop image realtime from bash?

Post by mikecolley »

Thank You Kalyk

I will try this and I will let you know if it works in LM17 Cinnamon Live DVD session, but I won't get to it for a day or two.

- Mike
Kalyk
Level 5
Level 5
Posts: 769
Joined: Wed Mar 12, 2014 5:29 pm
Location: The Netherlands

Re: How can I change desktop image realtime from bash?

Post by Kalyk »

Just now tried it in a live environment and it doesn't work fully the same.
The cp-command doesn't make the background change in that situation as I tried it, but repeating the gsettings-command with the same filename after cp'ing a different picture to test.jpg does change it.
So it seems like a test in a live environment makes a little difference.
But if you have an installation somewhere: this doesn't break anything and can easily be rolled back.
Add (Solved) to the topic-title of the first post when appropriate so others know they might find a solution here.
mikecolley
Level 3
Level 3
Posts: 118
Joined: Fri May 20, 2011 5:41 am

Re: How can I change desktop image realtime from bash?

Post by mikecolley »

Hi Kalyk:

Thank you for your solution, IT WORKS!

It works from the command line and it works from a bash script file too. Happy Happy.

However if I ssh into the PC from another PC it doesn't work -- I don't care, I just won't do that.

Here is what worked for me:

Code: Select all

mint@192.168.3.5 Pictures $ 
mint@192.168.3.5 Pictures $ 
mint@192.168.3.5 Pictures $ pwd
/home/mint/Pictures
mint@192.168.3.5 Pictures $ whoami
mint
mint@192.168.3.5 Pictures $ ll
total 64
drwxr-xr-x  2 mint mint  4096 Sep 17 23:51 .
drwxr-xr-x 28 mint mint  4096 Sep 17 23:34 ..
-rw-r--r--  1 mint mint 27318 Sep 17 23:50 20140917-2347-55-01.jpg
-rw-r--r--  1 mint mint 27318 Sep 17 23:51 desktop.jpg
mint@192.168.3.5 Pictures $ gsettings set org.cinnamon.desktop.background picture-uri 'file:///home/mint/Pictures/desktop.jpg' 
mint@192.168.3.5 Pictures $ 
mint@192.168.3.5 Pictures $ 
mint@192.168.3.5 Pictures $ # Here is how I got the prompt:
mint@192.168.3.5 Pictures $ cat ~/.bashrc
alias myip="echo `hostname -I | cut -d' ' -f1`"
        if [[ ${EUID} == 0 ]] ; then
                # show root@ when we don't have colors
                PS1='\u@\h \W \$ '
        else
# was -----                PS1='\u@\h \w \$ '
                PS1="\u@`hostname -I | cut -d' ' -f1` \W \$ "
        fi

mint@192.168.3.5 Pictures $ 
and it takes a couple seconds for the command to complete because I am running this on an under-powered Acer One Netbook, but after about three seconds, the desktop image changes.

If I copy a different .jpg on top of /home/mint/Pictures/desktop.jpg nothig happens until I repeat the gsettings command. That's ok, I can handle that.

What I intend to do is explicitly callout the most recent picture the camera has taken about once every 30 seconds and make that picture be the desktop background.

It works! It works! Happy Happy!

Thank You Kalyk
Kalyk
Level 5
Level 5
Posts: 769
Joined: Wed Mar 12, 2014 5:29 pm
Location: The Netherlands

Re: [Solved]: How can I change desktop image realtime from b

Post by Kalyk »

It was fun to figure out so thanks for asking, might be using it myself.

As for SSH, it is textbased so can't work.
With gsettings you change the settings for the Gnome/Cinnamon-environment you're in.
You could do a remote desktop and change it in that session so it works on the machine you're working from, because then it is your graphical environment.
If you want to have the remote thing solved then it is important to know the exact way you want it to work and what kind of machine you are connecting from, what OS etc.
Add (Solved) to the topic-title of the first post when appropriate so others know they might find a solution here.
scryan

Re: [Solved]: How can I change desktop image realtime from b

Post by scryan »

The command tells the desktop what picture to use right?
So why are you copying the picture you want to use, renaming it then pointing it at that again?

For instance if your moving picture1.jpg to wallpaper.jpg then using the command to set wallpaper.jpg as background... Why the extra step? Either way you script needs to know the actual file name it is setting as the new wallpaper, so rather then copy your picture to a generic name, then run the command on that generic name... Why not just run that command on the picture you wanted?

so rather then

Code: Select all

cd ~/Pictures
gsettings set  org.cinnamon.desktop.background picture-uri 'file:///home/mintuser/Pictures/test.jpg'
cp dexxus_4714207610.jpg test.jpg
(which by the way, you want to copy first, THEN set the picture right?)
Why are you not just using

Code: Select all

gsettings set  org.cinnamon.desktop.background picture-uri 'file:///home/mintuser/Pictures/dexxus_4714207610.jpg'
Not running mint or cinnamon so I can't test that for you but it should be the same thing in less steps?

If you want to use a generically named picture though (I do this because I don't run a DE, I set my background with the program feh at boot with a command in a config file, pointing at a ~/Pictures/wallpaper so I don't have to edit the config to change backgrounds), consider making a symbolic link rather then just copying the file, as there is no need to store the data twice when you can just create a link.
Locked

Return to “Cinnamon”