From 5da47fc3e5afb2dedda0d068070f0efa0dc4773b Mon Sep 17 00:00:00 2001 From: danix Date: Tue, 21 Mar 2023 18:15:34 +0100 Subject: [PATCH] added send to device shell script. --- bin/send-to-device.sh | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 bin/send-to-device.sh diff --git a/bin/send-to-device.sh b/bin/send-to-device.sh new file mode 100755 index 0000000..a320e0f --- /dev/null +++ b/bin/send-to-device.sh @@ -0,0 +1,54 @@ +#! /bin/bash + +QARMA="/usr/bin/qarma" +KDECONN=$(which kdeconnect-cli) +CHOICE=/tmp/choose_devices +OUTPUT=/tmp/share_output + + +function scan_devices() { + if [[ -f $CHOICE ]]; then + rm $CHOICE + fi + DEV_NAMES=$(${KDECONN} -a --name-only) + DEV=$($QARMA --list --text="Select your device" --hide-header "$DEV_NAMES" > $CHOICE) + case $? in + 0 ) + # echo "${KDECONN} --share figa -n \"$(cat $CHOICE)\"" + DEVICE="$(cat $CHOICE)" + ;; + 1 ) + $QARMA --info --title="Exiting!" --text="No device was selected." + DEVICE="" + ;; + -1 ) + $QARMA --error --title="Ooops!!" --text="Something unexpected happened." + DEVICE="" + ;; + esac + printf %s "$DEVICE" +} + +function send_file() { + if [[ -f $OUTPUT ]]; then + rm $OUTPUT + fi + if [[ -f $1 && -n $2 ]]; then + FILE=$1 + DEST=$2 + echo -e "Sharing to ${DEST} - " > $OUTPUT + $KDECONN --share "$FILE" -n "$DEST" 2>&1 >> $OUTPUT + $QARMA --info --title="Share to Device" --text="$(cat $OUTPUT)" + else + echo "no device selected" + fi +} + +if [[ -f $1 ]]; then + # we have a file to share + SHARED=$1 + SHAREDTO=$(scan_devices) + send_file "$SHARED" "$SHAREDTO" +else + echo "tell me what to send" +fi -- 2.20.1