├── LICENSE ├── README.md ├── dark-mode.py └── preview.gif /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Siddharth Dushantha 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dark-mode 2 | 3 | > Control the macOS dark mode from the terminal 4 | 5 | *Requires macOS 10.10 or later. Tested on macOS 10.13* 6 | 7 |

8 | 9 | 10 |

11 | 12 | ## Installation 13 | 14 | ```bash 15 | # clone the repo 16 | $ git clone https://github.com/sdushantha/dark-mode.git 17 | ``` 18 | 19 | ## Usage 20 | ```bash 21 | Usage: python3 dark-mode.py [command] 22 | 23 | Commands 24 | Toggle dark mode 25 | on Enable dark mode 26 | off Disable dark mode 27 | status Dark mode status 28 | ``` 29 | 30 | ## License 31 | MIT License 32 | 33 | Copyright (c) 2018 Siddharth Dushantha 34 | -------------------------------------------------------------------------------- /dark-mode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import subprocess as sp 4 | import sys 5 | import platform 6 | from os import system 7 | 8 | prefix = """osascript -e 'tell application \"System Events\" to tell appearance preferences to""" 9 | get_status = "defaults read -g AppleInterfaceStyle" 10 | 11 | 12 | def show_help(): 13 | help_message = """ 14 | Usage: python3 dark-mode.py [command] 15 | 16 | Commands 17 | Toggle dark mode 18 | on Enable dark mode 19 | off Disable dark mode 20 | status Dark mode status 21 | """ 22 | 23 | print(help_message) 24 | 25 | 26 | def status(): 27 | """ 28 | Get current status, "Dark Mode" or "Light Mode". 29 | """ 30 | 31 | try: 32 | status = sp.check_output(get_status.split(), stderr=sp.STDOUT).decode() 33 | status = status.replace("\n", "") 34 | 35 | except sp.CalledProcessError: 36 | return "Light Mode" 37 | 38 | if status == "Dark": 39 | return "Dark Mode" 40 | 41 | 42 | def set_mode(mode): 43 | """ 44 | Set the mode 45 | 46 | :param mode: The mode to be set 47 | :type mode: str 48 | """ 49 | 50 | if mode == "Null": 51 | mode = "not dark mode" 52 | 53 | cmd = prefix+" set dark mode to {}'".format(mode) 54 | 55 | # I know I should use subprocess but it messes up. 56 | # I will try to fix it. 57 | system(cmd) 58 | 59 | 60 | def main(): 61 | if platform.system() != "Darwin": 62 | print("Can only be run on macOS!") 63 | sys.exit() 64 | 65 | if len(sys.argv) == 1: 66 | set_mode("Null") 67 | 68 | elif sys.argv[1] == "on": 69 | set_mode("True") 70 | 71 | elif sys.argv[1] == "off": 72 | set_mode("False") 73 | 74 | elif sys.argv[1] == "status": 75 | print(status()) 76 | 77 | else: 78 | show_help() 79 | 80 | 81 | if __name__=="__main__": 82 | main() 83 | -------------------------------------------------------------------------------- /preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdushantha/dark-mode/982384638b9e1053511301acd6cc1a13481f42f6/preview.gif --------------------------------------------------------------------------------