[Mint] Switch Desktop Preferences Easily?


Recommended Posts

Hi guys,

 

I'm running Linux Mint on my laptop, which I use for business and personal use. With that in mind, I would like to change a couple of settings quickly; namely the desktop background. I would like it so that either with the touch of a keyboard shortcut or moving the mouse to a hot corner I can tell the system to change the background from profile1 to profile2. I'd also like the profiles to switch the screensaver choice, but I'll work with the desktop background for now.

 

Hot corners seem to be the easiest way to go. I've got one that runs a command to start the screensaver and lock the screen when touched, so it seems the best option to have another corner that when touched runs a batch file. However, my coding knowledge is lacking and this is where I need help. Using pseudo-code I need the following to happen:

If profile1 is active run profile2
OR
If profile2 is active run profile1

Profile1:
Set desktop background destination folder to <destination folder>
Set screensaver to <screensaver choice>

Profile2:
Set desktop background destination folder to <destination folder>
Set screensaver to <screensaver choice>

It's obviously achievable given that you can manually switch through the GUI, but I'm looking for something that will just run with the touch of a button (or as my intentions are, the selection of a hot corner). It's not a big deal, but I want to really use the fact that Linux can be customized for every situation.

 

Someone is going to say, "why don't you just have two accounts? One for work and one for play?" I would prefer to avoid this option if possible since I access work and personal documents at the same time. Plus, I know that the commands to switch backgrounds and screensavers is there, that is how we're able to do it through the GUI. A batch job would achieve these changes without me needing to switch accounts when I get home.

Link to comment
Share on other sites

Why not just right click a picture and choose "set as wallpaper"?

 

I'm not entirely sure in this department, but that code looks right.

Link to comment
Share on other sites

1 minute ago, Mindovermaster said:

Why not just right click a picture and choose "set as wallpaper"?

 

I'm not entirely sure in this department, but that code looks right.

I get that it's not a hardship to right click and say "set as wallpaper" or "change desktop background" on the desktop, but if we include the screensaver in the mix it takes that extra little bit of time and I'd like a quick batch file to run to make the changes instead.

Link to comment
Share on other sites

8 minutes ago, Nick H. said:

I get that it's not a hardship to right click and say "set as wallpaper" or "change desktop background" on the desktop, but if we include the screensaver in the mix it takes that extra little bit of time and I'd like a quick batch file to run to make the changes instead.

Oh, OK. Wasn't sure where you were going there. ;)

 

Any reason you need to keep changing it, at all? 2nd one pron or something and you don't want it at work? :laugh:

Link to comment
Share on other sites

2 minutes ago, Mindovermaster said:

Any reason you need to keep changing it, at all? 2nd one pron or something and you don't want it at work? :laugh:

Haha, I knew that was going to be asked!

 

Since I am using it as a business laptop as well as personal, I would like that my business logo is displayed when I'm out in the field. But I don't like being reminded of work when I'm at home and instead prefer more scenic backgrounds. For the screensaver, sure I would like to switch between a GLslideshow of scantily-clad women and the xmatrix screensaver (you've got to keep the geek-look in some places!) :p

  • Haha 2
Link to comment
Share on other sites

I use Variety and just have a slideshow ... but also (I believe) hotkeys can be set up to change the wallpaper.

 

Can do it so that your chosen ones are the only ones in that folder, as it's folder-based.

Link to comment
Share on other sites

So I'm making some progress thanks to the Mint forums. Here is the script at the moment:

if [ $(gsettings get org.cinnamon.desktop.background.slideshow slideshow-enabled) == "false" ] ; then
    gsettings set org.cinnamon.desktop.background.slideshow slideshow-enabled true    
    gsettings set org.cinnamon.desktop.background.slideshow image-source "directory:///home/username/Pictures/Wallpaper"
    gsettings set org.cinnamon.desktop.background.slideshow delay 10
    gsettings set org.cinnamon.desktop.background.slideshow random-order true
    
else

    gsettings set org.cinnamon.desktop.background.slideshow slideshow-enabled false
    gsettings set org.cinnamon.desktop.background picture-uri "file:///home/username/Pictures/logo.png"
fi

But it's really weird. After some trial and error I have found that however I rearrange the coding the script will always jump to the commands after  the "else" part of the script. It seems to disregard all the commands before then. So for example, if I inverse the code above (changing the if variable as well) and execute it then it will start the slideshow with the correct settings. With the code as it is above it jumps straight to setting the static logo. Also, if I break the code in to two scripts, removing the if...else idea then each set of commands work on their own. It's like the system doesn't recognize the if...else command and just ignores whatever is before "else."

 

@HaggisI meant to mention you before to see if you could offer any insight, and right now I am very confused and could do with some help. ;)

 

I'll worry about the screensaver later. If I can get this done that's already a win.

 

EDIT: There must be something in that "if" condition that isn't behaving right, although I'm not sure how that explains why the system skips the commands until the "else" bit.

Link to comment
Share on other sites

For them that are interested, a guy over at Linux Mint figured out where the script was going wrong. It requires the following at the beginning of the script:

#!/bin/bash

So for the full script:

#!/bin/bash
if [ $(gsettings get org.cinnamon.desktop.background.slideshow slideshow-enabled) == "false" ] ; then

    gsettings set org.cinnamon.desktop.background.slideshow slideshow-enabled true    
    gsettings set org.cinnamon.desktop.background.slideshow image-source "directory:///home/username/destination_folder"
    gsettings set org.cinnamon.desktop.background.slideshow delay 10
    gsettings set org.cinnamon.desktop.background.slideshow random-order true
    
else

    gsettings set org.cinnamon.desktop.background.slideshow slideshow-enabled false
    gsettings set org.cinnamon.desktop.background picture-uri "file:///home/username/path_to_image_blahblah.jpg"
fi

I've already asked about why that makes a difference to how the system interprets the script, but for now I have my wallpaper sorted! As I said in the thread, next up is dealing with the screensaver. But this is an awesome progression!

  • Like 4
Link to comment
Share on other sites

While I posted a link to my thread on the Mint forums, I figured I would paste the information here as well with regards to the need for putting bash at the start:

Quote

Without a shebang, and launched with no parameters a script will default to running in a 'dash' shell in Mint. Dash is the default because it's quick and lightweight and it's been the default in Ubuntu and Debian based distros for a number of years mainly because the various background scripts that run on login are quicker run in dash.

The terminal runs a 'bash' shell - bash is a bit slower to execute, a bit heavier, but has more features, and most shell script tutorials you'll find on the net assume bash is being used. It's compatible with dash in that a script that runs under dash will run under bash, but a script that runs under bash won't necessarily run under dash if it uses some bash specific syntax.

In the code snippet I posted I (without really thinking about it) used a bash specific syntax for the if test (the double ==). A single = would have been been both dash and bash compliant in this context.

It makes sense if I think about it. If you're going to use code that the terminal doesn't normally work with then you're going to need to tell the terminal which language to speak/interpret.

 

Now to do some searching for commands relating to xscreensaver! :p

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.