|
|
@ -0,0 +1,150 @@ |
|
|
|
#!/usr/bin/env bash |
|
|
|
# dmenu_kdeconnect.sh is a script based off of these scripts |
|
|
|
# [polybar-kdeconnect] https://github.com/HackeSta/polybar-kdeconnect |
|
|
|
# [polybar-kdeconnect-scripts] https://github.com/witty91/polybar-kdeconnect-scripts |
|
|
|
# Added features |
|
|
|
# - Removed polybar as a Dependencies (since I use dwm) |
|
|
|
# - Integration with a variety of file managers |
|
|
|
# - Implementation as one simplified shell script |
|
|
|
# - utilize sh instead of bash |
|
|
|
|
|
|
|
#TODO |
|
|
|
# 1. Allow different dmenu colors based on the battery percentage |
|
|
|
# 2. Make the script no sh complaint |
|
|
|
# 3. Implement a contacts list to make sms messaging easier |
|
|
|
|
|
|
|
# Dependancies |
|
|
|
# -dmenu |
|
|
|
# -kdeconnect |
|
|
|
# -zenity, nnn, or ranger |
|
|
|
# -qt5-tools |
|
|
|
# -dbus |
|
|
|
# -dunst |
|
|
|
|
|
|
|
# options |
|
|
|
# nnn |
|
|
|
# zenity |
|
|
|
# ranger |
|
|
|
Picker='zenity' |
|
|
|
|
|
|
|
# Color Settings of dmenu |
|
|
|
COLOR_DISCONNECTED='#000' # Device Disconnected |
|
|
|
COLOR_NEWDEVICE='#ff0' # New Device |
|
|
|
COLOR_BATTERY_90='#fff' # Battery >= 90 |
|
|
|
COLOR_BATTERY_80='#ccc' # Battery >= 80 |
|
|
|
COLOR_BATTERY_70='#aaa' # Battery >= 70 |
|
|
|
COLOR_BATTERY_60='#888' # Battery >= 60 |
|
|
|
COLOR_BATTERY_50='#666' # Battery >= 50 |
|
|
|
COLOR_BATTERY_LOW='#f00' # Battery < 50 |
|
|
|
|
|
|
|
# Icons shown in dmenu |
|
|
|
ICON_SMARTPHONE='' |
|
|
|
ICON_TABLET='' |
|
|
|
SEPERATOR='|' |
|
|
|
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
|
|
|
|
|
|
|
ping -q -c 1 1.1.1.1 > /dev/null || "$(notify-send "check internet connection" && exit)" |
|
|
|
|
|
|
|
show_devices (){ |
|
|
|
IFS=$',' |
|
|
|
devices="" |
|
|
|
# for all the devices avalable |
|
|
|
for device in $(dbus-send --print-reply --session --dest=org.mconnect /org/mconnect/manager org.mconnect.DeviceManager.ListDevices | cut -f1 -d"[" | cut -f1 -d "]" | tail -2); do |
|
|
|
#get the device info |
|
|
|
deviceobj=$(echo "$device" | cut -f2 -d"\"" | tr -d '\n' | xargs) |
|
|
|
devicename=$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:Name | grep -E string | cut -f2 -d"\"") |
|
|
|
isreach="$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:IsConnected | grep -E boolean | cut -b 26-)" |
|
|
|
devicetype=$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:DeviceType | grep -E string | cut -f2 -d"\"") |
|
|
|
istrust="$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:Allowed | grep -E boolean | cut -b 26-)" |
|
|
|
if [ "$isreach" = "true" ] && [ "$istrust" = "true" ];then |
|
|
|
#is connected |
|
|
|
battery="$(dbus-send --print-reply --session --dest=org.mconnect $deviceobj org.freedesktop.DBus.Properties.Get string:org.mconnect.Device.Battery string:Level | grep -e uint32 | cut -b 25-)%" |
|
|
|
icon=$(get_icon $battery $devicetype) |
|
|
|
# colors="$(get_colors $battery)" |
|
|
|
# echo "$colors" |
|
|
|
show_menu "$devicename | $battery $icon" $deviceid $battery |
|
|
|
devices+="$devicename $battery $icon $SEPERATOR" |
|
|
|
elif [ "$isreach" = "false" ] && [ "$istrust" = "true" ];then |
|
|
|
#nothing is found |
|
|
|
devices+="$(get_icon -1 $devicetype)$SEPERATOR" |
|
|
|
else |
|
|
|
#found but not yet paired |
|
|
|
icon=$(get_icon -2 $devicetype) |
|
|
|
show_pmenu $devicename $deviceid |
|
|
|
devices+="$devicename $icon $SEPERATOR" |
|
|
|
fi |
|
|
|
done |
|
|
|
} |
|
|
|
|
|
|
|
SendKeys(){ |
|
|
|
output="?" |
|
|
|
TEMPFILE=/tmp/VimFloat |
|
|
|
> $TEMPFILE |
|
|
|
st -t "vim-anywhere" -n 'popup' -e "${EDITOR:-vi}" -c 'startinsert' $TEMPFILE |
|
|
|
xsel -i < $TEMPFILE |
|
|
|
output=$(xsel -o) |
|
|
|
notify-send "$output" |
|
|
|
kdeconnect-cli --device "$*" -k "$output" |
|
|
|
} |
|
|
|
|
|
|
|
#displays a menu for the connected device |
|
|
|
show_menu () { |
|
|
|
optionNum=5 |
|
|
|
options=$(printf "Send SMS\\nSend File\\nFind Device\\nPing\\nUnpair\\nkeys\\n") |
|
|
|
options+=$(printf "\\nRefresh\\n") |
|
|
|
menu=$(echo $options | dmenu -i -p $1 -l $optionNum ) |
|
|
|
case "$menu" in |
|
|
|
*'Send File') |
|
|
|
[ $Picker == 'nnn' ] && kdeconnect-cli --share "file://$($TERMINAL nnn -p -)" -d $2 ; |
|
|
|
[ $Picker == 'zenity' ] && kdeconnect-cli --share "file://$(zenity --file-selection)" -d $2 ; |
|
|
|
if [ $Picker == 'ranger' ]; then |
|
|
|
mkdir -p /tmp/ranger/ && touch /tmp/ranger/sentfile |
|
|
|
kdeconnect-cli --share "file://$($TERMINAL ranger --choosefile=/tmp/ranger/sentfile)" -d $2 |
|
|
|
fi;; |
|
|
|
*'Unpair' ) kdeconnect-cli --unpair -d $2 ;; |
|
|
|
*'Send SMS' ) |
|
|
|
message=$(echo 'OTW' | dmenu -i -p "Msg to send") |
|
|
|
recipient=$(echo '14039199518' | dmenu -i -p "Recipient's phone #") |
|
|
|
kdeconnect-cli --send-sms "$message" --destination "$recipient" -d $2 ;; |
|
|
|
*'Refresh' ) |
|
|
|
kdeconnect-cli --refresh;; |
|
|
|
*'Notification' ) |
|
|
|
Notification_menu $notification1 $2;; |
|
|
|
*'keys' ) |
|
|
|
SendKeys "$2";; |
|
|
|
esac |
|
|
|
} |
|
|
|
|
|
|
|
show_pmenu () { |
|
|
|
menu="$(printf "Pair Device" | dmenu -i -p "$1" )" |
|
|
|
case "$menu" in |
|
|
|
*'Pair Device') kdeconnect-cli --pair -d $2 ;; |
|
|
|
esac |
|
|
|
} |
|
|
|
#still a work in progress |
|
|
|
# get_colors () { |
|
|
|
# case $1 in |
|
|
|
# "-1") colors="-nb \"$COLOR_DISCONNECTED\" -nf \"#000\" " ;; |
|
|
|
# "-2") colors="-nb \"$COLOR_NEWDEVICE\" -nf \"#000\" ";; |
|
|
|
# 5*) colors="-nb \"$COLOR_BATTERY_50\" -nf \"#000\" ";; |
|
|
|
# 6*) colors="-nb \"$COLOR_BATTERY_60\" -nf \"#000\" ";; |
|
|
|
# 7*) colors="-nb \"$COLOR_BATTERY_70\" -nf \"#000\" ";; |
|
|
|
# 8*) colors="-nb \"$COLOR_BATTERY_80\" -nf \"#000\" ";; |
|
|
|
# *) colors="-nb \"$COLOR_BATTERY_LOW\" -nf \"#000\" ";; |
|
|
|
# 9*|100) colors="-nb \"$COLOR_BATTERY_90\" -nf \"#000\" ";; |
|
|
|
# esac |
|
|
|
# echo $colors |
|
|
|
# } |
|
|
|
|
|
|
|
get_icon () { |
|
|
|
if [ "$2" = "tablet" ] |
|
|
|
then |
|
|
|
ICON=$ICON_TABLET |
|
|
|
else |
|
|
|
ICON=$ICON_SMARTPHONE |
|
|
|
fi |
|
|
|
echo $ICON |
|
|
|
} |
|
|
|
show_devices |
|
|
|
#vim:ft=sh |