#!/bin/sh
# Copyright (C) 2025 stemsee
function sendfn (){
Machines="$(tailscale status | grep -e idle -e online | awk '{print $1,$2}' | cut -f2 -d' ')"
machine="$(printf "%s\n" $Machines | yad --title="Devices on $ts tailnet" --text="Select Multiple Targets" --item-separator=' ' --list --check --column="Available" --height=300 --width=300 --center --multiple | cut -f1 -d'|')"
file=$(echo "$1" | cut -c8-)
while read line
do
tailscale file cp "$file" "$line":
done<<<"$machine"
}; export -f sendfn
export ts="$(tailscale status | grep -e idle -e online | awk '{print $3}')"
yad --dnd --geometry=20x10+80+80 --title="TS - $ts" --text=" S \n E \n d N d \n D " --command="bash -c \"sendfn "%s" \"" --on-top --button=" RECEIVE ":"bash -c 'tailscale file get /root/Downloads'" &