Apologies I know this will seem pedestrian -- please forgive me, I'm a newbie. I have low vision, so I'd like to automatically toggle different "display profiles" based on whether there is an external display connected. I'm looking to have the following variables set when there is an external display connected:

;; ** Full-screen mode (set-frame-parameter nil 'fullscreen 'fullboth)

;; ** Large font (set-face-attribute 'default nil :height 1500)

And I would like the following if the external display is disconnected (or there is no external display detected):

;; ** Full-screen mode (set-frame-parameter nil 'fullscreen 'fullboth)

;; ** Large font (set-face-attribute 'default nil :height 1000)

(the full screen appears in both because I've found that often emacs will be demoted to a small window after a display switch.

I'm running emacs on Mac OS 10.13.6. If it isn't straightforward to have this done automatically, is there a way to tie each profile to a global key-binding to set the respective variables so display can be optimized manually? Right now I go into the init file and C-x C-e for each of these.

1 Answer 1


Not sure just what you're asking, but I guess information about whether you currently have multiple monitors would help. For that, you can use functions display-monitor-attributes-list and frame-monitor-attributes.

See the Elisp manual, node Multiple Terminals.

The length of the list returned by display-monitor-attributes-list tells you how many monitors you have.

Doc string:

display-monitor-attributes-list is a compiled Lisp function in frame.el.

(display-monitor-attributes-list &optional DISPLAY)

Return a list of physical monitor attributes on DISPLAY.

DISPLAY can be a display name, a terminal name, or a frame. If DISPLAY is omitted or nil, it defaults to the selected frame’s display.

Each element of the list represents the attributes of a physical monitor. The first element corresponds to the primary monitor.

The attributes for a physical monitor are represented as an alist of attribute keys and values as follows:

geometry -- Position and size in pixels in the form of (X Y WIDTH HEIGHT)

workarea -- Position and size of the work area in pixels in the form of (X Y WIDTH HEIGHT)

mm-size -- Width and height in millimeters in the form of (WIDTH HEIGHT)

frames -- List of frames dominated by the physical monitor

name (*) -- Name of the physical monitor as a string

source (*) -- Source of multi-monitor information as a string

where X, Y, WIDTH, and HEIGHT are integers. X and Y are coordinates of the top-left corner, and might be negative for monitors other than the primary one. Keys labeled with (*) are optional.

The "work area" is a measure of the "usable" display space. It may be less than the total screen size, owing to space taken up by window manager features (docks, taskbars, etc.). The precise details depend on the platform and environment.

The source attribute describes the source from which the information was obtained. On X, this may be one of: "Gdk", "XRandr", "Xinerama", or "fallback".

A frame is dominated by a physical monitor when either the largest area of the frame resides in the monitor, or the monitor is the closest to the frame if the frame does not intersect any physical monitors. Every (non-tooltip) frame (including invisible ones) in a graphical display is dominated by exactly one physical monitor at a time, though it can span multiple (or no) physical monitors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.