modern_lisp-machine/misc/scripts/send_image_telegram.sh

45 lines
1.7 KiB
Bash
Raw Normal View History

2024-09-08 20:03:55 +00:00
EXEC_SHELL_PATH=$(command -v bash)
send_most_recent_image_via_telegram() {
# Specify the correct folder paths
folder_path_x="/mnt/Data/mpv-screenshots/"
folder_path_y="/mnt/Data/mpv-screenshots/screenshots/"
# Check if both folders exist
if [ ! -d "$folder_path_x" ] || [ ! -d "$folder_path_y" ]; then
echo "Error: One or both folders do not exist."
return 1
fi
# Get the most recent file from FolderX
most_recent_x=$(find "$folder_path_x" -maxdepth 1 \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.bmp" -o -iname "*.tiff" \) -exec stat --format='%Y %n' {} + | sort -nr | head -n 1)
# Get the most recent file from FolderY
most_recent_y=$(find "$folder_path_y" -maxdepth 1 \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.bmp" -o -iname "*.tiff" \) -exec stat --format='%Y %n' {} + | sort -nr | head -n 1)
# Compare the modification times and choose the most recent file
if [ "$(echo "$most_recent_x" | cut -d' ' -f 1)" -gt "$(echo "$most_recent_y" | cut -d' ' -f 1)" ]; then
most_recent_file="$most_recent_x"
else
most_recent_file="$most_recent_y"
fi
# Check if telegram-desktop is installed
if ! command -v telegram-desktop &> /dev/null; then
echo "Error: telegram-desktop is not installed."
return 1
fi
# Activate telegram-desktop window
wmctrl -x -a telegram-desktop
# Send the most recent image file via telegram-desktop
telegram-desktop -sendpath "$(echo "$most_recent_file" | cut -d' ' -f 2-)"
echo "Sent most recent image file via telegram-desktop: $(echo "$most_recent_file" | cut -d' ' -f 2-)"
}
# Execute the function
send_most_recent_image_via_telegram