
下に旅行写真があるネストされたディレクトリ構造があります~/Pictures/Shotwell-Import/YYYY/MM/DD/
。
私のデスクトップの背景をこの画像からランダムに選択したいです。
残念ながら、Cinnamonは一番上の画像があるフラットディレクトリを期待しているようです。
この制限を回避する方法を知っていますか?
ありがとうございます!
答え1
回避策としてクローン操作を使用できます。
サンプルディレクトリ構造を含むガイドライン。必要に応じて修正してください。
入れ子になったディレクトリ構造が次の場所にあるとします。/home/USERNAME/Pictures/Shotwell-Import
シェルスクリプトの作成
次の場所にスクリプトファイルを作成します/home/USERNAME/Pictures/set-random-image.sh
。
#!/bin/bash
# Change to directory containing this script.
# See http://stackoverflow.com/a/3355423/246724
cd "$(dirname "$0")"
# Set the pictures directory
PICDIR="/home/USERNAME/Pictures/Shotwell-Import"
# Randomly pick one of the pictures.
# See http://www.webupd8.org/2009/11/3-lines-script-to-automatically-change.html
PICFILE=$(find $PICDIR -iregex '.*\.\(jpeg\|jpg\|png\)' | shuf -n1)
# Prevent a "dconf-WARNING **: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY"
# Omit the last letter of "cinnamon-session" for the character limit in pgrep.
PID=$(pgrep -u $LOGNAME cinnamon-sessio)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
# Set Cinnamon background image.
# Other desktop environments need different command.
gsettings set org.cinnamon.desktop.background picture-uri "file://$PICFILE"
スクリプト/ファイル権限を設定しよう
このスクリプトを実行できるようにファイル権限を構成します。その後、スクリプトを一度実行します。
cd /home/USERNAME/Pictures
# Copy an example picture to mybkg.jpg
./set-random-image.sh
# Permission problems?
chmod u+rwx set-random-image.sh
# Now it should work!
./set-random-image.sh
# Do it again a few times, and see the background change.
# If this does not work, this tutorial will be useless to you.
./set-random-image.sh
./set-random-image.sh
背景画像の構成
それでは、背景画像として設定してみてください。コマンドラインを使用してこれを行うこともできますが、UIで実行する方がより透明であると思います。
設定>背景ダイアログボックスを開きます。
設定タブで、障害を負う「背景をスライドショーで再生」。クローンジョブを作成するので、スライドは必要ありません。
[画像]タブで/home/USERNAME/Pictures/mybkg.jpg
背景画像として整理します。フォルダを追加して/home/USERNAME/Pictures
フォルダ内の画像を選択するには、左下隅にある「+」アイコンが必要です。
クローンジョブの設定
タイプcrontab -e
。 1分ごとに変更するには、次の行を追加してください。
* * * * * /home/USERNAME/Pictures/set-random-image.sh
しばらく待って背景が変わるかどうかを確認してください。
注:Cinnamonの設定とファイルのコピー
この回答の以前のバージョンでは、スクリプトはシナモン設定を変更するのではなく、画像をデフォルトの場所にコピーしました。利点は、他のデスクトップ環境でも同じように機能することです。欠点は、毎分不要なディスク書き込みがSSDに有害である可能性があることです。妄想が最終的に勝利したので、この回答を変更しました。