Skip to content

Instantly share code, notes, and snippets.

@Hayao0819
Last active January 27, 2020 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hayao0819/7aaf0f7210bf3b8c482cbf772fb9cc61 to your computer and use it in GitHub Desktop.
Save Hayao0819/7aaf0f7210bf3b8c482cbf772fb9cc61 to your computer and use it in GitHub Desktop.
Xfce環境でマウスの速度を簡単に変更できるスクリプト
#!/usr/bin/env bash
# 設定
setting="$HOME/.mouse-speed"
# setting="$HOME/Desktop/config"
# 現在のマウスの一覧を取得
mouse_list=$(xfconf-query -c pointers -vl | grep Acceleration | awk '{print $1}')
mouse_list=${mouse_list//\/Acceleration//}
mouse_list=($(echo $mouse_list))
for ((i=0; i<${#mouse_list[@]}; i++)); do
mouse_list[$i]=${mouse_list[$i]//'/'/''}
done
function usage () {
echo "Easy-Mouse-Speed-Changer"
echo
echo "-h : このヘルプを表示します。"
echo "-l : マウスの一覧を表示します。"
echo "-m [番号] : マウスを指定します。入力する番号は「-l」で確認してください。"
echo "-s : 現在の設定されている値を表示します。"
echo "-v [数字] : 値を指定します。設定する値は「+3」(3増加させる)や「-2」(2減少させる)、「4」(4にする)などを使用できます。"
exit 0
}
function show_list () {
for ((i=0; i<${#mouse_list[@]}; i++)); do
echo -n "$i : "
echo "${mouse_list[$i]}"
done
}
# 設定ファイル作成
[[ ! -f $setting ]] && touch $setting
# オプション解析
while getopts 'm:v:hls' arg; do
case "${arg}" in
m) select=${OPTARG};;
v) value=${OPTARG} ;;
h) usage;;
l) show_list; exit 0;;
s) show_only=true ;;
"") : ;;
* ) exit 1;;
esac
done
# マウスを聞く
if [[ ! -f $setting ]]; then
if [[ ${#mouse_list[@]} = 1 ]]; then
echo "自動的に${mouse_list[0]}が選択されました"
select=0
elif [[ ${#mouse_list[@]} = 0 ]]; then
echo "マウスが選択されていません。"
elif [[ -n $select ]]; then
:
else
select=0
echo "変更するマウスを選択してください。"
echo
show_list
echo
echo -n "default=0 ==> "
read select
fi
selected_mouse=${mouse_list[$select]}
else
source $setting
fi
# 現在の値を表示
current_var=$(xfconf-query -c pointers -p "/${selected_mouse}/Acceleration")
echo 現在は$current_varに設定されています。
[[ $show_only = true ]] && exit 0
# 聞いた結果をチェック
if [[ ${#mouse_list[@]} < $select || -z ${mouse_list[$select]} ]]; then
echo "存在する値を入力してください。"
exit 1
fi
# 設定を保存
echo "#!/usr/bin/env bash" > $setting
echo >> $setting
echo -n "selected_mouse=" >> $setting
echo "${selected_mouse}" >> $setting
if [[ -z $value ]]; then
echo -n "変更する値を入力してください(例:+1、-1、3など) : "
read value
fi
if [[ ${value::1} = "-" || ${value::1} = "+" ]]; then
set_value=$( echo ${current_var}${value} | bc )
else
set_value=$value
fi
if [[ $set_value = 0 || $set_value < 0 ]]; then
echo "0より小さくすることはできません。"
exit 1
fi
xfconf-query -c pointers -p "/${selected_mouse}/Acceleration" -s ${set_value}
echo "マウス${selected_mouse}の速度は${set_value}に設定されました。"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment