
ユニットランチャーの自動非表示オプションを切り替えるキーボードショートカットを作成したいと思います。ランチャーの非表示動作をプログラムで変更する方法この作業を実行するために Python スクリプトを作成しようとしました。次に、キーボード ショートカットを使用してそれを実行する方法を理解する必要があります。
私のスクリプトは次のようになります:
#!/bin/python
AUTOHIDE=$(dconf read /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode)
if (AUTOHIDE==1):
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 0
else:
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 1
しかし、ターミナルからスクリプトを実行すると ('python scriptname.py' を実行) 機能しません。$ 記号で「無効な構文」エラーが発生します。
私は Python に関する知識 (またはスクリプトの書き方全般) がほとんどないことを知っておく必要があります (ヘルプと例を探すために Web で数時間検索しただけです)。
実際の質問は次のとおりです。
- 何を間違えたのでしょうか?
- これに複雑なアプローチを選択しましたか? その場合、どうすればもっと簡単に実行できますか?
答え1
Python 風にやりたい場合。
#!/bin/python
import subprocess
AUTOHIDE = subprocess.check_output (["/usr/bin/dconf", "read", "/org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode"])
if (AUTOHIDE==1):
subprocess.call (["/usr/bin/dconf", "write", "/org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode", "0"])
else:
subprocess.call (["/usr/bin/dconf", "write", "/org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode", "1"])
サブプロセスを作成してプログラムを実行する必要があります。
これはbashスクリプトのバージョンです
#!/bin/bash
AUTOHIDE=$(dconf read /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode)
if [[ $AUTOHIDE -eq 1 ]]
then
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 0
else
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 1
fi
ショートカットは次のように割り当てられますこれ。
答え2
簡単に行う方法の 1 つは、カスタム ショートカットを作成することです。
システム設定 > キーボード > ショートカット > カスタムショートカットにアクセスし、「+」をクリックして新しいショートカットを追加し、コマンドボックスに次のコードを貼り付けます。
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 0
これにより、ランチャーを表示するためのショートカットが作成されます。ランチャーを非表示にするには、次のコマンドを追加して別のショートカットを作成する必要があります。
dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 1
もちろん、今では各機能ごとに 1 つのコマンドがありますが、それらを並べて配置すると非常に直感的になります。
答え3
Unity 2Dの場合、dconfの行は次のようになります。
/com/canonical/unity-2d/launcher/hide-mode
値が 2 である 3 番目のモード「Intellihide」もあります。