snipt

Ctrl+h for KB shortcuts

Bash

changewallpaper.sh

#!/bin/bash
# http://stackoverflow.com/questions/10374520/gsettings-with-cron

# TODO: At night only dark wallpapers.
#   Hora=$(date +%H)
#   case $Hora in
#              0? | 1[01]) dir=/caminho/para/folder/manha ;;
#              1[2-7] )  dir=/caminho/para/folder/tarde ;;
#               * ) dir=/caminho/para/folder/noite ;;
#   esac

# Wallpaper's directory.
dir="${HOME}/img/wallpapers/"

# Weird, but necessary thing to run with cron.
sessionfile=`find "${HOME}/.dbus/session-bus/" -type f`
export `grep "DBUS_SESSION_BUS_ADDRESS" "${sessionfile}" | sed '/^#/d'`

# Random wallpaper.
wallpaper=`find "${dir}" -type f | shuf -n1`

# Change wallpaper.
# http://bit.ly/HYEU9H
#gsettings set org.gnome.desktop.background picture-options "spanned"
gsettings set org.gnome.desktop.background picture-options "stretched"
gsettings set org.gnome.desktop.background picture-uri "file://${wallpaper}"
https://snipt.net/embed/180d5061afdaa5190a5bcce38c8c6fdc/
/raw/180d5061afdaa5190a5bcce38c8c6fdc/
180d5061afdaa5190a5bcce38c8c6fdc
bash
Bash
27
2019-05-27T05:00:28
True
False
False
Sep 26, 2012 at 08:02 PM
/api/public/snipt/47698/
changewallpapersh
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a> <a href="#L-13">13</a> <a href="#L-14">14</a> <a href="#L-15">15</a> <a href="#L-16">16</a> <a href="#L-17">17</a> <a href="#L-18">18</a> <a href="#L-19">19</a> <a href="#L-20">20</a> <a href="#L-21">21</a> <a href="#L-22">22</a> <a href="#L-23">23</a> <a href="#L-24">24</a> <a href="#L-25">25</a> <a href="#L-26">26</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="ch">#!/bin/bash</span> </span><span id="L-2"><a name="L-2"></a><span class="c1"># http://stackoverflow.com/questions/10374520/gsettings-with-cron</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c1"># TODO: At night only dark wallpapers.</span> </span><span id="L-5"><a name="L-5"></a><span class="c1"># Hora=$(date +%H)</span> </span><span id="L-6"><a name="L-6"></a><span class="c1"># case $Hora in</span> </span><span id="L-7"><a name="L-7"></a><span class="c1"># 0? | 1[01]) dir=/caminho/para/folder/manha ;;</span> </span><span id="L-8"><a name="L-8"></a><span class="c1"># 1[2-7] ) dir=/caminho/para/folder/tarde ;;</span> </span><span id="L-9"><a name="L-9"></a><span class="c1"># * ) dir=/caminho/para/folder/noite ;;</span> </span><span id="L-10"><a name="L-10"></a><span class="c1"># esac</span> </span><span id="L-11"><a name="L-11"></a> </span><span id="L-12"><a name="L-12"></a><span class="c1"># Wallpaper&#39;s directory.</span> </span><span id="L-13"><a name="L-13"></a><span class="nv">dir</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span><span class="s2">/img/wallpapers/&quot;</span> </span><span id="L-14"><a name="L-14"></a> </span><span id="L-15"><a name="L-15"></a><span class="c1"># Weird, but necessary thing to run with cron.</span> </span><span id="L-16"><a name="L-16"></a><span class="nv">sessionfile</span><span class="o">=</span><span class="sb">`</span>find <span class="s2">&quot;</span><span class="si">${</span><span class="nv">HOME</span><span class="si">}</span><span class="s2">/.dbus/session-bus/&quot;</span> -type f<span class="sb">`</span> </span><span id="L-17"><a name="L-17"></a><span class="nb">export</span> <span class="sb">`</span>grep <span class="s2">&quot;DBUS_SESSION_BUS_ADDRESS&quot;</span> <span class="s2">&quot;</span><span class="si">${</span><span class="nv">sessionfile</span><span class="si">}</span><span class="s2">&quot;</span> <span class="p">|</span> sed <span class="s1">&#39;/^#/d&#39;</span><span class="sb">`</span> </span><span id="L-18"><a name="L-18"></a> </span><span id="L-19"><a name="L-19"></a><span class="c1"># Random wallpaper.</span> </span><span id="L-20"><a name="L-20"></a><span class="nv">wallpaper</span><span class="o">=</span><span class="sb">`</span>find <span class="s2">&quot;</span><span class="si">${</span><span class="nv">dir</span><span class="si">}</span><span class="s2">&quot;</span> -type f <span class="p">|</span> shuf -n1<span class="sb">`</span> </span><span id="L-21"><a name="L-21"></a> </span><span id="L-22"><a name="L-22"></a><span class="c1"># Change wallpaper.</span> </span><span id="L-23"><a name="L-23"></a><span class="c1"># http://bit.ly/HYEU9H</span> </span><span id="L-24"><a name="L-24"></a><span class="c1">#gsettings set org.gnome.desktop.background picture-options &quot;spanned&quot;</span> </span><span id="L-25"><a name="L-25"></a>gsettings <span class="nb">set</span> org.gnome.desktop.background picture-options <span class="s2">&quot;stretched&quot;</span> </span><span id="L-26"><a name="L-26"></a>gsettings <span class="nb">set</span> org.gnome.desktop.background picture-uri <span class="s2">&quot;file://</span><span class="si">${</span><span class="nv">wallpaper</span><span class="si">}</span><span class="s2">&quot;</span> </span></pre></div> </td></tr></table>
bash, wallpaper