07 July 2014

Mint 17 Cinnamon: Wallpaper slideshow using crontab

I wanted to have a folder containing lots of pictures that would be used to change my desktop wallpaper every once in a while. If I added more pictures to the folder, they should be included automatically.

Before Mint 17 it was easy to use gsettings in your crontab to do this, but something had changed when they switched to Ubuntu 14.04 instead. I found a nice thread on AskUbuntu (http://askubuntu.com/questions/457016/how-to-change-gsettings-via-remote-shell) which solved a similar problem. I then adapted that solution to my own problem.

It turned out that if you try to run gsettings in crontab, it is missing an environment variable, which can be found using the script below.

1. Save this script file: pastebin link
I put mine in /home/dahlo/tools/wallpaper-change_cinnamon.bash


#!/bin/bash

# Search these processes for the session variable 
# (they are run as the current user and have the DBUS session variable set)
compatiblePrograms=( nemo pulseaudio trackerd nautilus )

# Attempt to get a program pid
for index in ${compatiblePrograms[@]}; do
    PID=$(pidof -s ${index})
    if [[ "${PID}" != "" ]]; then
        break
    fi
done
if [[ "${PID}" == "" ]]; then
    echo "Could not detect active login session"
fi

QUERY_ENVIRON="$(tr '\0' '\n' < /proc/${PID}/environ | grep "DBUS_SESSION_BUS_ADDRESS" | cut -d "=" -f 2-)"
if [[ "${QUERY_ENVIRON}" != "" ]]; then

    export DBUS_SESSION_BUS_ADDRESS="${QUERY_ENVIRON}"
    # echo "Connected to session:"
    # echo "DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}"

    # Script to randomly set Background from files in a directory

    # Directory Containing Pictures is given via command-line, could be hardcoded in there as well
    DIR=$1

    #DIR="/home/user/Picture"
    #DIR="/home/user/Documents/cultural-festivities/"

    # Command to Select a random jpg file from directory
    # Delete the *.jpg to select any file but it may return a folder
    PIC=$(find $DIR -type f -exec file {} \; | grep -o -P '^.+: \w+ image' | cut -d ':' -f 1 | shuf -n1)

    # Command to set Background Image
    gsettings set org.cinnamon.desktop.background picture-uri "file:///$PIC"



else
    echo "Could not find dbus session ID in user environment."
fi

2. Add it to your crontab and supply the path to the picture folder (/home/dahlo/tools/Wallpapers) as an argument.


# change wallpaper every 5 minutes
*/5 * * * * bash /home/dahlo/tools/wallpaper-change_cinnamon.bash /home/dahlo/tools/Wallpapers 


This will randomly select one of the image files in the folder you specify and use it as your desktop wallpaper.

13 March 2013

How to persistently change primary monitor in Linux Mint 14

I have 2 monitors connected, and of course the one i want to have as primary is not used as primary by the computer.

I read around on forums and the only suggestion i found was to use xrand to change primary monitor in a startup script. The problem was that my panels got all messed up by doing this, since the panels got initialized on the smaller screen first, and then changed to the larger screen once my script ran.

The soulution was very simple it turned out. Instead of using xrand, just change which monitor to use as primary in


  • ~/.config/monitors.xml


Find the screen you want to use as primary and change the


  • <primary>no</primary>


to


  • <primary>yes</primary>


No more startup scripts or any other messy things!


Thanks to AlbertP on the Linux Mint forums: http://forums.linuxmint.com/viewtopic.php?f=206&t=104497

01 September 2012

How to install Compiz in MATE in Linux Mint 13

It bugged my quite a lot that i could not blur the background in my transparent terminal in Linux Mint 13 Mate. Not only that, i missed many of the other Compiz features, like zoom, grid and other nice things. So i decided i had to install compiz :)

I googled around and found a couple of good guides, so i thought "Hey, there can always be one more guide!". So here we go:


TL;DR: the short version

$ sudo apt-get install compizconfig-settings-manager
$ compiz --replace

(Keep the terminal open until you are done. You will want Compiz to start automatically,  Control Center -> Startup Applications, and add a new post "Compiz" with the command "compiz --replace", without the "".

$ mateconf-editor
# Go to /desktop/mate/session/required_components/windowmanager and
replace "marco" with "compiz".

# Download and import this compiz profile in CompizConfig Settings Manager - Preferences - Profile & Backend - Import: http://pastebin.com/7d5h5vyq

$ sudo apt-get install gconf-editor
$ gconf-editor

# Enter themes name in /apps/metacity/general/theme (I settled for Mint-X)
# List of available themes in /usr/share/themes/ (no way to preview? :/ )

Log out and then back in again, and everything should be finished.


From this guide to start using compiz: http://community.linuxmint.com/tutorial/view/919

Copy of the content:

There is some things you have to do to get Compiz work.

Install the packet "compizconfig-settings-manager".

 In a terminal window write "compiz --replace"     (When you want
Compiz start automatic you can open Control Center -> Startup
Applications, and add a new post "Compiz" keeping the same command
"compiz --replace".

The CPU usage now raises a lot.  That is because there is two
competing window-managers running.
To stop that high CPU usage in MATE when running Compiz:

In a terminal type “mateconf-editor”

When the editor opens:
Go to /desktop/mate/session/required_components/windowmanager and
replace "marco" with "compiz".
Not much happens now,

Thats because nothing is checked in "Compiz Configuration Settings Manager".

Open the Compiz Configuration Settings Manager.

Check what compiz-functions you want to activate.

One you sure need, the "Window Decoration".

Then you can choose "Move Window" and things you find good for you.


I took a copy of my compiz config-file and put it on pastebin: http://pastebin.com/7d5h5vyq

Save the config as a file and import it in Compiz Configuration Settings Manager (Preferences - Profile & Backend - Import)


Now, the window decorations will look like crap (imho), so that has to change.

To change window decoration theme, install gconf-editor and follow the
2nd answer in this thread:
http://askubuntu.com/questions/98243/how-to-customise-window-decoration-whilst-using-compiz-on-xubuntu

installing gnome-tweak-tool would pull almost the entire Gnome as
dependencies. I had the same problem today and I didn't want to
install such a lot of unneeded stuff only to change one little setting
and spent some time researching how these things are related and it
seems it is indeed possible with gconf-editor (or gconftool-2) alone.

The key in gconf-editor is /apps/metacity/general/theme.

Type the name of an existing metacity theme into the text field (such
as greybird and note that greybird is starting with a LOWERcase letter
while most other themes are not!), hit enter and it should immediately
change.

You can also change the arrangement of window buttons in
/apps/metacity/general/button_layout (for example to move the window
buttons to the right side where they traditionally belong use this:
menu:minimize,maximize,close). Most other options in this section
describe window behavior rather than style and don't have any effect
on compiz, they would only be used by metacity.

I.e.  install gconf-editor and run it, and type the name of the theme you want in /apps/metacity/general/theme

I used Mint-X and was happy with it. The list of available themes:
$ ls -l /usr/share/themes/ 

(no way to preview? :/ )



And that should do it. I now have Linux Mint 13 Mate with Compiz :)

06 September 2010

Remap mouse buttons in Ubuntu 10.04, to have middle button as 'back' in browser

Ok, so i tried a bunch of programs, like btnx and imwheel, but nothing worked. Btnx worked, but had some weird side effects, such as holding down the alt key every time i pressed the mouse button, so i had to physically press the alt button on the keyboard to stop the 'alt signal'.

The solution was simple:

First, get the name for your mouse


$ xinput list

⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ PS/2 Generic Mouse id=11 [slave pointer (2)]
⎜ ↳ SynPS/2 Synaptics TouchPad id=12 [slave pointer (2)]
⎜ ↳ Macintosh mouse button emulation id=13 [slave pointer (2)]
⎜ ↳ Logitech Trackball id=16 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Sleep Button id=8 [slave keyboard (3)]
↳ HP Webcam [2 MP Macro] id=9 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=10 [slave keyboard (3)]



Find the mouse. My mouse has the name "Logitech Trackball".

A fancier mouse with more buttons will have a button for 'back' in the browser, so i wanted to set my middle mouse button to that signal.

First, just for fun, look at your current mouse map

$ xinput get-button-map "Logitech Trackball"
1 2 3 4 5 6 7


This is the standard map. The order of the numbers are 1 = left mb, 2 = middle mb, 3 = right mb, 4 = mwheel up, 5 = mwheel down

So what is 6 and 7? I have no idea :) But i know for a fact that 8 = Back on my mouse :)

I just tried mapping different numbers to my middle mouse button until it worked.

Like this:

$ xinput set-button-map "Logitech Trackball" 1 7 3 4 5 6 7

Tried it, and it did not work. So i increased it once more:

$ xinput set-button-map "Logitech Trackball" 1 8 3 4 5 6 7

And it worked! I did not even had to restart X or anything, it updated instantly.

To make the change permanent, you have to add this to some startup script. I added it to the startup applications thingy in Preferences >> Startup Applications. Simply write xinput set-button-map "Logitech Trackball" 1 8 3 4 5 6 7 in the command field.

27 August 2010

Creating a multi-partition usb drive with dual booting persistent Linux Mint and Puppy Linux

Wow, that title is really a mouth full :)

First off, i used other guides while doing this, and i would not have made it without them.
* http://tazbuntu.blogspot.com/2009/05/multibootin-with-unetbootin.html For getting the multibooting to work

So, i wanted a bootable usb-stick. I wanted Linux Mint, for obvious reasons, and also Puppy Linux, if i ever were to come across a old and crappy computer. To be extra picky, i also wanted the OS to be on a separate partition, since it looks messy with loads of weird linux-files in the root. I also wanted to be able to use the data-part of the stick in both windows and linux.

So, to put in in a list form:

* Boot Mint and Puppy
* Separate OS and data partitions
* Work in both Windows and Linux

Ok, so the first thing i discovered was that Windows for some weird reason will only read the first partition on a usb-stick..

1. Start Linux. I used Linux Mint 9. Whether you have it installed by default or use a live-cd doesnt matter.

2. Install programs needed. Gparted for partitioning, unetbootin for the puppy part.
sudo apt-get install gparted unetbootin

3. Partition your usb-stick.

- Start gparted.

- Remove all partitions on your usb-stick (this WILL delete everything you the usb-stick, so take care while doing it, and make sure it is your usb-stick you are deleting)

- Create the data partition that will work in both linux and windows. I used 12gb for this on my 16gb stick. Make the file system NTFS so that windows can read it. It is IMPORTANT to create this first in the beginning of the usb-stick, since windows only reads the first partition.

- Create the OS partition that will host your linux installs. Make this FAT32. (maybe ext will work?)

- Perform the changes with gparted if you have not already done so.

4. Download the latest Linux Mint and Puppy Linux isos. (just google it)

5. Use unetbootin to install Puppy Linux on the OS partition you just created.

6. Copy the entire OS partition to a folder called /puppy on the data-partition. This is just for storing it until later.

7. Format the OS partition to clear away puppy linux. Make sure it is still FAT32.

8. Use the "Startup Disc Creator" that is included in all later Ubuntu editions. It is for sure included in Linux Mint 9. Use it to install the linux mint iso you downloaded in step 4 onto the newly formated OS partition. Select a nice size for the "reserved extra space". I used 1 gb for this. This is where the persistence comes in. All changes you make will be saved in this space, so dont be cheap ;)

Ok, so now there is a data partition that works in windows, a persistent linux mint on it, and soon there will be puppy as well!

9. Copy the files from the /puppy folder from the data partition and place it in /puppy on the OS partition.

10. Edit /syslinux/syslinux.cfg on the OS partition. This is the grub menu that is displayed during boot. Puppy linux has to be inserted here to be able to choose it.

My file looked like this:

default vesamenu.c32
timeout 100

menu background splash.jpg
menu title Welcome to Linux Mint 9 Isadora
menu color border 0 #00eeeeee #00000000
menu color sel 7 #ffffffff #33eeeeee
menu color title 0 #ffeeeeee #00000000
menu color tabmsg 0 #ffeeeeee #00000000
menu color unsel 0 #ffeeeeee #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color timeout_msg 0 #ffffffff #00000000
menu color timeout 0 #ffffffff #00000000
menu color cmdline 0 #ffffffff #00000000
menu hidden
menu hiddenrow 6
label live
menu label Start Linux Mint
kernel /casper/vmlinuz
append noprompt cdrom-detect/try-usb=true persistent file=/cdrom/preseed/mint.seed boot=casper initrd=/casper/initrd.lz quiet splash --
menu default
label xforcevesa
menu label Start Linux Mint (compatibility mode)
kernel /casper/vmlinuz
append noprompt cdrom-detect/try-usb=true persistent file=/cdrom/preseed/mint.seed boot=casper xforcevesa initrd=/casper/initrd.lz ramdisk_size=1048576 root=/dev/ram rw noapic noapci nosplash irqpoll --
label memtest
menu label Memory Test
kernel memtest
label local
menu label Boot from local drive
localboot 0x80


Almost unreadable, so lets add some blank lines


default vesamenu.c32
timeout 100

menu background splash.jpg
menu title Welcome to Linux Mint 9 Isadora
menu color border 0 #00eeeeee #00000000
menu color sel 7 #ffffffff #33eeeeee
menu color title 0 #ffeeeeee #00000000
menu color tabmsg 0 #ffeeeeee #00000000
menu color unsel 0 #ffeeeeee #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color timeout_msg 0 #ffffffff #00000000
menu color timeout 0 #ffffffff #00000000
menu color cmdline 0 #ffffffff #00000000
menu hidden
menu hiddenrow 6

label live
menu label Start Linux Mint
kernel /casper/vmlinuz
append noprompt cdrom-detect/try-usb=true persistent file=/cdrom/preseed/mint.seed boot=casper initrd=/casper/initrd.lz quiet splash --
menu default

label xforcevesa
menu label Start Linux Mint (compatibility mode)
kernel /casper/vmlinuz
append noprompt cdrom-detect/try-usb=true persistent file=/cdrom/preseed/mint.seed boot=casper xforcevesa initrd=/casper/initrd.lz ramdisk_size=1048576 root=/dev/ram rw noapic noapci nosplash irqpoll --

label memtest
menu label Memory Test
kernel memtest
label local

menu label Boot from local drive
localboot 0x80


Ahh, much better!

Ok, so we have to add Puppy to the list

label puppy
menu label Puppy Linux 5.1.0
kernel /puppy/vmlinuz
append initrd=/puppy/initrd.gz pmedia=cd

should do the trick. And the final result should look like this:


default vesamenu.c32
timeout 100

menu background splash.jpg
menu title Welcome to Linux Mint 9 Isadora
menu color border 0 #00eeeeee #00000000
menu color sel 7 #ffffffff #33eeeeee
menu color title 0 #ffeeeeee #00000000
menu color tabmsg 0 #ffeeeeee #00000000
menu color unsel 0 #ffeeeeee #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color timeout_msg 0 #ffffffff #00000000
menu color timeout 0 #ffffffff #00000000
menu color cmdline 0 #ffffffff #00000000
menu hidden
menu hiddenrow 6

label live
menu label Start Linux Mint
kernel /casper/vmlinuz
append noprompt cdrom-detect/try-usb=true persistent file=/cdrom/preseed/mint.seed boot=casper initrd=/casper/initrd.lz quiet splash --
menu default

label xforcevesa
menu label Start Linux Mint (compatibility mode)
kernel /casper/vmlinuz
append noprompt cdrom-detect/try-usb=true persistent file=/cdrom/preseed/mint.seed boot=casper xforcevesa initrd=/casper/initrd.lz ramdisk_size=1048576 root=/dev/ram rw noapic noapci nosplash irqpoll --

label puppy
menu label Puppy Linux 5.1.0
kernel /puppy/vmlinuz
append initrd=/puppy/initrd.gz pmedia=cd

label memtest
menu label Memory Test
kernel memtest
label local

menu label Boot from local drive
localboot 0x80


Ok, now everything should be working. Reboot your computer and start from the usb-stick, and you should be greeted by grub!

A recommendation is to install PortableApps on the data partition from windows. After that, you will have a very functional usb-stick that has all the programs you need (PortableApps) and can even boot it's own OS if needed (Mint or Puppy).

01 June 2010

Recover a TrueCrypt volume after quick format

Background: I have an encrypted RAID0 array for storing data, and a SSD to install windows on. I had some problems with windows, so i decided to reinstall it. I did this without disconnecting the RAID-drives. (I mean, why should i have to?)

So, during a windows installation my encrypted data-drive got quick formated. Since an encrypted drive looks like random data when it is not mounted, I guess windows saw it fit to initialize my apparently unformatted RAW-drive without asking me..

The encrypted drive looked like a normal newly formated drive in windows, and i could mount it with truecrypt using the same password as before, but i was not able to read the drive that was mounted. It was unformatted according to windows.

Solution:

I used my rescue disc and restored the file header. I have no idea if this in necessary, but it did not take long and did not hurt, so i might as well write it here. I then used the data recovery program R-Tools to scan the mounted drive for files. Just like a normal drive. I have used Zero Assumption Recovery before, but i think R-Tools was much faster with equal results. Just took 4-5 hours to scan my 1.2TB drive.

After the scan it was just a matter of restoring the data on the damaged drive to another drive, and then copy it back again.