-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscfmt
More file actions
executable file
·64 lines (49 loc) · 1.64 KB
/
scfmt
File metadata and controls
executable file
·64 lines (49 loc) · 1.64 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env zsh
# Change macOS screenshot output format.
# Usage: scfmt png | jpg | ...
SUPPORTED_FORMATS=(png jpg jpeg gif tiff heic)
scfmt() {
cat <<EOF
Usage: $(basename "$0") <format>
Change the macOS screenshot format.
Supported (known) formats:
${SUPPORTED_FORMATS[*]}
Examples:
$(basename "$0") png
$(basename "$0") jpg
Current format: $(defaults read com.apple.screencapture type 2>/dev/null || echo "unknown")
EOF
}
# Show help if no args or -h/--help
if [[ $# -ne 1 || "$1" == "-h" || "$1" == "--help" ]]; then
scfmt
exit 0
fi
# Check if running on macOS
if [[ "$(uname)" != "Darwin" ]]; then
echo "Error: This script only works on macOS." >&2
exit 1
fi
format="${1:l}" # lowercase
# Warn if format is not in our known list
if [[ " ${SUPPORTED_FORMATS[*]} " != *" $format "* ]]; then
echo "Warning: '$format' is not in the known list: ${SUPPORTED_FORMATS[*]}" >&2
echo "macOS may still support it, but double-check." >&2
fi
echo "Setting screenshot format to '$format'..."
# Check if defaults command succeeds
if ! defaults write com.apple.screencapture type "$format"; then
echo "Error: Failed to set screenshot format." >&2
exit 1
fi
# Restart UI server so change takes effect
if ! killall SystemUIServer >/dev/null 2>&1; then
echo "Warning: Could not restart SystemUIServer. You may need to log out and back in." >&2
fi
# Verify the change
new_format=$(defaults read com.apple.screencapture type 2>/dev/null)
if [[ "$new_format" == "$format" ]]; then
echo "✓ Successfully set screenshot format to '$format'."
else
echo "Warning: Format was set, but verification shows '$new_format' instead of '$format'." >&2
fi