emacs - system type

How to determine operating system in elisp?

https://stackoverflow.com/questions/1817257/how-to-determine-operating-system-in-elisp

The system-type variable:

system-type is a variable defined in C source code.

Documentation: Value is symbol indicating type of operating system you are using.

Special values:

  1. gnu compiled for a GNU Hurd system.
  2. gnu/linux compiled for a GNU/Linux system.
  3. darwin compiled for Darwin (GNU-Darwin, Mac OS X, …).
  4. ms-dos compiled as an MS-DOS application.
  5. windows-nt compiled as a native W32 application.
  6. cygwin compiled using the Cygwin library.

Anything else indicates some sort of Unix system.

Conditional logic in .el files

For folks newer to elisp, a sample usage:

(if (eq system-type 'darwin)
  ; something for OS X if true
  ; optional something if not
)

Or, if we don’t care for the else-form and have multiple then-forms,

(when (eq system-type 'darwin)
  ; do this
  ; and this ...
)

How to determine the system-type of your computer?

Paste it in your scratch buffer and press C-j after the outermost parenthesis.

(pcase system-type
  ;; GNU/Linux or WSL
  (gnu/linux
   (message "This is GNU/Linux"))

  ;; macOS
  (darwin
   (message "This is macOS"))

  ;; Windows
  (windows-nt
   (message "This is Windows"))

  ;; BSDs
  (berkeley-unix
    (message "This is a BSD"))

  ;; Other operating system
  (_
   (message "Unknown operating system")))

Links to this note