Skip to content

Instantly share code, notes, and snippets.

@funasoul
Last active October 15, 2022 17:22
Show Gist options
  • Save funasoul/2b5d4e47d702943d006f6413613ca644 to your computer and use it in GitHub Desktop.
Save funasoul/2b5d4e47d702943d006f6413613ca644 to your computer and use it in GitHub Desktop.
macOS, Linux, OpenBSD等で画面の解像度を取得
#!/usr/bin/env zsh
_has () {
return $( whence $1 &>/dev/null )
}
getresolution () {
# returns current resolution
if [[ "$OSTYPE" == "darwin"* ]]; then
system_profiler SPDisplaysDataType | awk '/Resolution:/{print $2 "x" $4}'
elif _has xrandr; then
xrandr | awk '/\*/{print $1}'
elif _has xdpyinfo; then
xdpyinfo | awk '/dimensions/{print $2}'
fi
}
getresolution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment