Skip to content

Instantly share code, notes, and snippets.

@syohex
Created February 28, 2012 14:33
Show Gist options
  • Save syohex/1932867 to your computer and use it in GitHub Desktop.
Save syohex/1932867 to your computer and use it in GitHub Desktop.
Get screen resolution on Mac OSX
(with-temp-buffer
(shell-command
"osascript -e 'tell application \"Finder\" to get bounds of window of desktop'" t)
(goto-char (point-min))
(if (re-search-forward "[0-9]+, [0-9]+, \\([0-9]+\\), \\([0-9]+\\)")
(let ((width (buffer-substring-no-properties
(match-beginning 1) (match-end 1)))
(height (buffer-substring-no-properties
(match-beginning 2) (match-end 2))))
(mapcar #'string-to-int (list width height)))))
(when (executable-find "xdpyinfo")
(with-temp-buffer
(shell-command "xdpyinfo" t)
(goto-char (point-min))
(when (re-search-forward "dimensions:\s+\\([0-9]+\\)x\\([0-9]+\\)" nil t)
(let ((width (buffer-substring-no-properties
(match-beginning 1) (match-end 1)))
(height (buffer-substring-no-properties
(match-beginning 2) (match-end 2))))
(mapcar #'string-to-int (list width height))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment