dconf の変更のスクリプト

dconf の変更のスクリプト

大学の Ubuntu マシン用に、テーマや背景などを設定するための dconf オーバーライドを設定する簡単なスクリプトを作成しました。しかし、ログイン画面の背景を正しく設定できないようです。

この目的のためのスクリプトのセクション:

#Set login background and remove dots
echo "Setting lightdm dconf settings"
xhost +SI:localuser:lightdm
su lightdm -c "gsettings set com.canonical.unity-greeter background '/background.png'"
su lightdm -c "gsettings set com.canonical.unity-greeter draw-grid false"

これらの同じコマンドは、lightdm ユーザーとしてログインしているターミナルに直接入力した場合にも機能します。次に例を示します。

sudo su lightdm -s /bin/bash
gsettings set com.canonical.unity-greeter background '/background.png'
gsettings set com.canonical.unity-greeter draw-grid false

壁紙を細かく設定する

コマンドは機能するのにスクリプトが機能しない理由について何か考えはありますか?

ありがとう

答え1

私がこれを解決した方法は次のとおりです。「sudo bash」を実行する代わりに、またはあなたの場合は「sudo -c」を実行する代わりに (これにより、ユーザーを変更するときにスクリプトが一時停止するか、単に機能しなくなります)、3 つの小さなスクリプトを実行します。

(各スクリプトを「chmod +x script_name.sh」で実行可能にすることを忘れないでください)

最初のスクリプトは install.sh です:

sudo cp third_script.sh /tmp         # Copy third_script to tmp for easier access
sudo chmod 0755 /tmp/third_script.sh # This needs to be executable by lightdm
sudo bash second_script.sh           # Runs next file
sudo rm /tmp/third_script.sh         # Now we can remove the third script

次に、second_script.sh で lightdm を xhost に追加し、3 番目のスクリプト ファイルを lightdm ユーザーとして実行します。

#!/bin/bash
echo "$USER"                         # To see if root is running the script
xhost +SI:localuser:lightdm
su lightdm -s /tmp/third_script.sh

そして、 third_script で魔法が起こります:

#!/bin/bash
echo "$USER"                         # To see if lightdm is running the script
gsettings set com.canonical.unity-greeter background '/background.png'
gsettings set com.canonical.unity-greeter draw-grid false

これは私にとってはうまくいきました! もっと簡単な方法があれば教えてください。

関連情報