The output file name is automatic (timestamp) and fixed.
You want a save file dialog popup.
If you cancel the save dialog, the image still should be copied to clipboard.
If you pick a file name, save it to disk as well as copy to clipboard.
Solution outline
We want an interactive save dialog program that runs in Wayland (since using wl-copy) and can return the selected path or cancel.
On X11, one would use zenity --file-selection --save or kdialog --getsavefilename. On Wayland, zenity often works fine if installed.
zenity --file-selection --save allows prompting for a save filename, user can cancel (exit code non-zero or empty output).
Steps
Capture the screenshot image data (PNG) from slurp|grim into a variable or a temporary file
Run zenity --file-selection --save to ask user for save location
If user selects a file, save the image data to that file
Regardless, copy the image data to clipboard with wl-copy
Example implementation
bash
#!/bin/bash
# Create a temporary file to save the screenshot data before clipboard and possible write
tmpfile=$(mktemp --suffix=.png)
# Take the screenshot, save to tmpfile
slurp | grim -g - - > "$tmpfile"
# Ask user for save location (with default filename)
default_filename="$(date +'%Y-%m-%d-%H%M%S').png"
savepath=$(zenity --file-selection --save --confirm-overwrite --filename="$HOME/Pictures/screenshots/$default_filename" --title="Save Screenshot As")
# If user provided a path, save file there
if [[ -n "$savepath" ]]; then
cp "$tmpfile" "$savepath"
fi
# Copy image to clipboard regardless of saving or not
wl-copy < "$tmpfile"
# Remove temp file
rm "$tmpfile"
Notes:
zenity pretty much works on Wayland (assuming your environment supports GUI apps)
--confirm-overwrite asks to confirm if file exists
You can customize default filename and folder
If user clicks cancel or closes dialog, savepath is empty and no save happens, but clipboard is set
wl-copy reads from the PNG file and sets clipboard
One liner version (not recommended for readability):