Created
December 31, 2024 05:02
-
-
Save shanecelis/33d50e4ec0b4dae389ef70ddd2b1c879 to your computer and use it in GitHub Desktop.
Record a window excluding title bar of a macOS application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# record-window | |
function usage() { | |
echo "usage: record-window [-hf] [-n window-number] <application> <capture.mov>" >&2; | |
echo " -h help; show usage (this)" >&2; | |
echo " -f force recording (remove previous output file if present)" >&2; | |
echo "Record a window excluding title bar of an application (case-sensitive)" >&2; | |
} | |
window_number="1"; | |
force=0; | |
while getopts n:hf opt; do | |
case $opt in | |
h) usage; exit 1;; | |
f) force=1;; | |
n) window_number="$OPTARG";; | |
*) echo "error: invalid option given." >&2; usage; exit 2; | |
esac | |
done | |
shift $[ OPTIND - 1 ] | |
if [ $# -ne 2 ]; then | |
usage; | |
exit 3; | |
fi | |
app="$1"; | |
capture="$2"; | |
window_header="28"; | |
rect=$(osascript <<EOF 2>&1 | tr -d ' ' | |
set windowHeader to $window_header | |
tell application "System Events" | |
tell process "$app" | |
activate | |
tell window $window_number | |
set thePosition to position | |
set theSize to size | |
log ((item 1 of thePosition)&((item 2 of thePosition) + windowHeader) & (item 1 of theSize) & ((item 2 of theSize) - windowHeader)) | |
end tell | |
end tell | |
end tell | |
EOF); | |
if [ $force -eq 1 ] && [ -f "$capture" ]; then | |
rm "$capture"; | |
fi | |
screencapture -v -R$rect "$capture"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment