How to determine the operating system in elisp?

How to programmatically determine which Emacs OS is running in ELisp?

I would like to run different code in .emacs depending on the OS.

+70
emacs elisp
Nov 30 '09 at 0:14
source share
7 answers

system-type variable:

 system-type is a variable defined in `C source code'. Its value is darwin Documentation: Value is symbol indicating type of operating system you are using. Special values: `gnu' compiled for a GNU Hurd system. `gnu/linux' compiled for a GNU/Linux system. `darwin' compiled for Darwin (GNU-Darwin, Mac OS X, ...). `ms-dos' compiled as an MS-DOS application. `windows-nt' compiled as a native W32 application. `cygwin' compiled using the Cygwin library. Anything else indicates some sort of Unix system. 
+79
Nov 30 '09 at 0:37
source share

For people newer to elisp, a usage example:

 (if (eq system-type 'darwin) ; something for OS X if true ; optional something if not ) 
+63
Jun 19 '10 at 3:23
source share

I created a simple macro to easily run code depending on the system type:

 (defmacro with-system (type &rest body) "Evaluate BODY if `system-type' equals TYPE." (declare (indent defun)) `(when (eq system-type ',type) ,@body)) (with-system gnu/linux (message "Free as in Beer") (message "Free as in Freedom!")) 
+17
01 Oct '14 at 8:48
source share

In .emacs there is not only a variable system-type , but also a window-system . This is useful when you want to select one option only x, or to configure a terminal or macro.

+9
Nov 30 '09 at 23:39
source share

Basically, they already answered it, but for those who are interested, I just tested it on FreeBSD, and there the reported value was "berkeley-unix".

+2
May 16 '13 at 6:03
source share

There is also (at least 24/25) system-configuration if you want to customize the differences in the build system.

0
Feb 08 '17 at 16:52
source share

Now there is also a Linux subsystem for Windows (bash for Windows 10), where system-type is gnu/linux . To detect this type of system, use:

 (if (string-match "Microsoft" (with-temp-buffer (shell-command "uname -r" t) (goto-char (point-max)) (delete-char -1) (buffer-string))) (message "Running under Linux subsystem for Windows") (message "Not running under Linux subsystem for Windows") ) 
0
Jul 18 '17 at 19:56 on
source share



All Articles