-
Notifications
You must be signed in to change notification settings - Fork 0
/
rofi-grim.sh
45 lines (40 loc) · 1.37 KB
/
rofi-grim.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
# Take a screenshot using grim command and save it with a temporary file name
tmp_file=$(mktemp /tmp/screenshot_XXXXXX.png)
grim -t jpeg -q 100 $tmp_file
while true; do
# Use Rofi prompt to ask for a file name
file_name=$(echo -n "" | rofi -dmenu -p "Enter file name")
# Check if a file name was entered
if [[ -z "$file_name" ]]; then
notify-send "No file name entered. Aborting."
exit 1
fi
if [[ -f $HOME/pictures/$file_name.jpg ]]; then
choice=$(echo -e "rename\nreplace\nkeep & ignore" | rofi -dmenu -p "File with the same name exists!")
case "$choice" in
"rename")
continue
;;
"replace")
mv "$tmp_file" "$HOME/pictures/$file_name.jpg"
notify-send "Screenshot replaced the existing picture."
break
;;
"keep & ignore")
rm $tmp_file
notify-send "Screenshot discarded. Existing picture kept."
break
;;
*)
notify-send "Invalid choice or no action taken. Aborting."
rm $tmp_file
exit 1
;;
esac
else
mv "$tmp_file" "$HOME/pictures/$file_name.jpg"
notify-send "Screenshot saved as $file_name.jpg"
break
fi
done