improve screenshot script
This commit is contained in:
@@ -489,7 +489,7 @@ binds {
|
|||||||
// Mod+Space { switch-layout "next"; }
|
// Mod+Space { switch-layout "next"; }
|
||||||
// Mod+Shift+Space { switch-layout "prev"; }
|
// Mod+Shift+Space { switch-layout "prev"; }
|
||||||
|
|
||||||
Mod+P { spawn "sh" "-c" "niri msg action screenshot && ~/.config/niri/copy-latest-screenshot.sh"; }
|
Mod+P { spawn "~/.config/niri/copy-latest-screenshot.sh"; }
|
||||||
Mod+Ctrl+P { screenshot-screen; }
|
Mod+Ctrl+P { screenshot-screen; }
|
||||||
Mod+Alt+P { screenshot-window; }
|
Mod+Alt+P { screenshot-window; }
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
screenshot_dir="$HOME/Pictures/Screenshots"
|
screenshot_dir="$HOME/Pictures/Screenshots"
|
||||||
remote_target="mac-attio:~/screenshot.png"
|
remote_target="mac-attio:~/screenshot.png"
|
||||||
|
timeout=3 # seconds
|
||||||
|
|
||||||
notify() {
|
notify() {
|
||||||
DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus" \
|
DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus" \
|
||||||
@@ -9,21 +10,39 @@ notify() {
|
|||||||
notify-send "$@"
|
notify-send "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Record existing files
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
files=("$screenshot_dir"/*.png)
|
existing_files=("$screenshot_dir"/*.png)
|
||||||
latest_file=""
|
existing_count=${#existing_files[@]}
|
||||||
if (( ${#files[@]} )); then
|
|
||||||
latest_file=$(ls -1t "${files[@]}" | head -n 1)
|
# Take screenshot
|
||||||
|
niri msg action screenshot
|
||||||
|
|
||||||
|
# Wait for new file (timeout in 0.1s intervals)
|
||||||
|
deadline=$((timeout * 10))
|
||||||
|
count=0
|
||||||
|
|
||||||
|
while (( count < deadline )); do
|
||||||
|
files=("$screenshot_dir"/*.png)
|
||||||
|
if (( ${#files[@]} > existing_count )); then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 0.1
|
||||||
|
((count++))
|
||||||
|
done
|
||||||
|
|
||||||
|
# Check if a new file appeared
|
||||||
|
if (( ${#files[@]} <= existing_count )); then
|
||||||
|
exit 0 # Canceled or failed, silent exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "${latest_file:-}" ]]; then
|
# Get the new file (most recent)
|
||||||
notify "Screenshot upload" "No screenshots found in $screenshot_dir"
|
latest_file=$(ls -1t "${files[@]}" | head -n 1)
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# Small delay to ensure file is fully written
|
||||||
|
sleep 0.1
|
||||||
|
|
||||||
|
# Upload
|
||||||
if scp -q "$latest_file" "$remote_target"; then
|
if scp -q "$latest_file" "$remote_target"; then
|
||||||
notify "Screenshot upload" "Uploaded $(basename "$latest_file")"
|
notify "Screenshot" "Uploaded to Mac"
|
||||||
else
|
|
||||||
notify "Screenshot upload" "Upload failed"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user