3 # autorandr_nitrogen_wallpaper
4 # Copyright (c) 2015, Ondra 'Kepi' KudlĂk, http://kepi.cz
6 # Simple script to switch wallpapers when autorandr change profile
11 # 1. place this script (or better symlink it from autorandr location)
12 # to ~/.config/autorandr/postswitch
13 # 2. run "nitrogen" and set wallpapers for current profile as you wish
14 # 3. run ~/.config/autorandr/postswitch savebg
15 # 4. repeat steps 2-3 for any profile you wish
20 # Permission is hereby granted, free of charge, to any person obtaining
21 # a copy of this software and associated documentation files (the
22 # "Software"), to deal in the Software without restriction, including
23 # without limitation the rights to use, copy, modify, merge, publish,
24 # distribute, sublicense, and/or sell copies of the Software, and to
25 # permit persons to whom the Software is furnished to do so, subject to
26 # the following conditions:
28 # The above copyright notice and this permission notice shall be
29 # included in all copies or substantial portions of the Software.
31 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 NITROGEN_HOME="$HOME/.config/nitrogen"
40 NITROGEN_BG="$NITROGEN_HOME/bg-saved.cfg"
42 # try to detect profile
43 PROFILE=$(autorandr 2>&1| grep detected |awk '{ print $1 }')
44 [[ -n "$PROFILE" ]] || exit 1
46 PROFILE_BG_FILE="bg-saved.$PROFILE.cfg"
47 PROFILE_BG="$NITROGEN_HOME/$PROFILE_BG_FILE"
49 # save background for detected profile
50 if [[ $1 = 'savebg' ]]; then
51 # nitrogen config doesnt exist, instruct to run it first
52 if [[ ! -f "$NITROGEN_BG" ]]; then
53 echo "wallpaper: you need to first run 'nitrogen' and set your wallpapers"
56 # nitrogen config exists but is broken symlink, just remove it and instruct to run it first
57 if [ ! -e "$NITROGEN_BG" ] ; then
58 /usr/bin/unlink "$NITROGEN_BG"
59 echo "wallpaper: you need to first run 'nitrogen' and set your wallpapers (config was broken)"
63 /bin/cp -L "$NITROGEN_BG" "$PROFILE_BG"
65 # load background for detected profile
67 # we have some profile background config for this setup
68 if [[ -f "$PROFILE_BG" ]]; then
69 # nitrogen original file exists and not symlink
70 if [[ -f "$NITROGEN_BG" ]] && [[ ! -L "$NITROGEN_BG" ]]; then
71 echo "wallpaper: Backing up nitrogen saved bg to $NITROGEN_BG.backup"
72 /bin/mv "$NITROGEN_BG" "$NITROGEN_BG".backup
76 echo "wallpaper: Found saved wallpaper for profile $PROFILE - changing"
77 ln -f -s "$PROFILE_BG_FILE" "$NITROGEN_BG"
81 echo "wallpaper: No saved wallpaper found for profile $PROFILE"