top | item 37053666

(no title)

hank_z | 2 years ago

If anyone is looking for an alternative, I have been using my script below for two years without any issue.

--edit--

I do not know how to format code here.

--edit--

Another attempt to format code here.

# Step 1 Save script below to your local drive. For example, `/Users/xxxx/Documents/Scripts/DarkMode/darkModeWatcher.sh`

  #!/bin/zsh
  # ref: https://unix.stackexchange.com/a/526097
  # start time is 18:33 -> 18 * 60 * 60 + 33 * 60 = 66780
  # end time is 07:33 -> 07 * 60 * 60 + 33 * 60 = 27180
  # install gdate via `brew install gdate`
  
  if [[ $(uname -m) == 'arm64' ]]; then
      secsSinceMidnight=$(( $(/opt/homebrew/bin/gdate +%s) - $(/opt/homebrew/bin/gdate -d '00:00:00' +%s) ))
  else
      secsSinceMidnight=$(( $(/usr/local/bin/gdate +%s) - $(/usr/local/bin/gdate -d '00:00:00' +%s) ))
  fi
  
  if [[ $secsSinceMidnight -lt 27180 || $secsSinceMidnight -gt 66780 ]]; then
      # turn on dark mode
      osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to true'
  else
      # turn off dark mode
      osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to false'
  fi

  
# Step 2 run `crontab -e` and add script below

  # cron job for enabling macOS dark mode periodically
  # darkModeWatcher script is executed 60s after reboot. After that, it is executed at 35 mins of each hour if the display is not asleep.
  # replace xxxx with your username
  @reboot sleep 60 && /bin/zsh /Users/xxxx/Documents/Scripts/DarkMode/darkModeWatcher.sh >> /Users/xxxx/Library/Logs/systemDarkModeWatcher.log 2>&1
  35 */1 * * * if [[ -n "$(/usr/sbin/system_profiler SPDisplaysDataType | /usr/bin/grep 'Asleep')" ]]; then newDisplayStatus=0; else newDisplayStatus=1; fi && if [[ $newDisplayStatus == 1 ]]; then /bin/zsh /Users/xxxx/Documents/Scripts/DarkMode/darkModeWatcher.sh >> /Users/xxxx/Library/Logs/systemDarkModeWatcher.log 2>&1 ; fi

discuss

order

dingosity|2 years ago

FYI... last time I tried, I could get the equivalent of a HTML <PRE> block by putting two spaces at the beginning of every line. Here's an example. Each line was indented two spaces:

  #include <stdio.h>
  
  int main() {
    printf( "Bonjour, totes le monde!\n" );
    return( 0 );
  }
Looks like it worked. It looks like it's rendering with a mono font.

hank_z|2 years ago

Thanks. It works.