LionyxML / auto-dark-emacs

Auto-Dark-Emacs is an auto changer between 2 themes, dark/light, following MacOS, Linux or Windows Dark Mode settings
GNU General Public License v2.0
140 stars 34 forks source link

Applescript detection method incorrectly used in terminal on macOS #37

Closed porterjamesj closed 8 months ago

porterjamesj commented 9 months ago

Hi,

Thanks for continuing to work on this package and getting in on MELPA! I've been using my own fork for years but am now back on this one :)

I'm happily using it fine it GUI, but there appears to be a bug in Terminal on macOS. Specifically, the code for determining if Applescript should be used as the detection method is:

 (and (eq system-type 'darwin)
       (fboundp 'ns-do-applescript))

However, this is incorrect. When I try to use auto-dark in the terminal. this evaluates to t because ns-do-applescript is bound. Then, when you try to evaluate Applescript, as auto-dark does later, you get an error:

Window system is not in use or not initialized

The best way I can think of to fix it would be to use (eq window-systemns)` instead, which for me at least (on macOS 11 and Emacs 29.1) correctly evaluates to true in GUI, false in terminal.

LionyxML commented 9 months ago

Hello @porterjamesj 😊,

Thank you for bringing this to my attention. The behavior does seem a bit unusual.

Would you be interested in submitting a pull request (PR)?

ascarter commented 8 months ago

@LionyxML @porterjamesj I attached a PR that fixes it for me when I set auto-dark-allow-osascript in my init.el:

;; Automatically adjust for light/dark modes
(use-package auto-dark
  :config
  (setq auto-dark-dark-theme 'modus-vivendi
    auto-dark-light-theme 'modus-operandi)
  (when (not window-system) (setq auto-dark-allow-osascript t))
  (auto-dark-mode t)
  )
LionyxML commented 8 months ago

Nice catch @porterjamesj , thanks @ascarter for the PR! It is now merged and will be soon available on MELPA.