Shifty icon indicating copy to clipboard operation
Shifty copied to clipboard

Custom scripting on Night Shift & Dark Mode toggle

Open sscherfke opened this issue 7 years ago • 7 comments

It would be nice if Shifty would also change the Terminal profile when (un)setting Dark Mode. This would only require a check box, two input fields for the theme names and some AppleScript. :-)

Please see https://stefan.sofa-rockers.org/2018/10/23/macos-dark-mode-terminal-vim/ for details.

sscherfke avatar Oct 24 '18 20:10 sscherfke

Considering some people use different terminal emulators (e.g. iTerm), maybe it could be an idea to add the ability to open a file (which can be an AppleScript or Shell script file) instead?

If there's interest in this (and support from @thompsonate) I could soon add a pull request for this.

nsalminen avatar Oct 28 '18 15:10 nsalminen

Yeah, I think running an AppleScript or Shell script file at the time Dark Mode is set would be a good implementation of this. Pull requests are welcome!

(Sorry for the late response)

thompsonate avatar Nov 11 '18 18:11 thompsonate

@nsalminen Yes, this sounds good. Two separate files / command lines (one for each mode) would be nice, b/c it would make it easier to check which mode we are currently in.

I haven’t done any programming in Swift so far, so I’m not sure whether I can contribute any code.

sscherfke avatar Nov 12 '18 16:11 sscherfke

I could probably cook this up, but what would be the preferred implementation for this?

  1. Do we want to script when Night Shift switches, when the theme is changed, or both? (the second happens only once the other with rules can get toggled much more often)
  2. Do we want to support only AppleScript which can be executed with its own API, or the accept just shell scripts which we execute with the Process API?
  3. Do we want to let the user paste the script and save it in the preferences or we let the user point to a script in some location?
  4. I think the best way to expose this feature is in the preferences. Do we add another section like "Advanced" dedicated to this (and possibly some future features, like maybe more complex rules), or do we simply add another row in the General section, with a checkbox there?

choco avatar Nov 29 '18 23:11 choco

@choco

  1. I think it makes sense to only run the scripts when Dark Mode is togggled, because the scripts are ment to supplement Dark Mode. If the user checked the option to automaitcally toggle Dark Mode, the scripts will also be run automatically
  2. I would just run the execectuables that the user provides. These can be bash scripts, shell scripts or whatever and the user can easily use their preferred language and easily extend their scripts.
  3. I would point to the script location, e.g.
    • Run on Dark Mode: /Users/name/toggle_darkmode.sh on
    • Run on Light Mode: /Users/name/toggle_darkmode.sh off
  4. An advanced section sounds good to me. :)

sscherfke avatar Nov 30 '18 06:11 sscherfke

  1. Definitely both when Night Shift switches and when the appearance changes. This issue and #48 show interest in both options. I'm also thinking it might be useful to have an option to run scripts just on a scheduled shift but not when the user toggles Night Shift.
  2. I think both would be ideal. AppleScript could also be executed with the Process API with osascript <file>.scpt
  3. I think the issue with pointing to a location is the possibility that the user could move or delete the file without realizing it. A better solution is to copy the file to somewhere in the ~/Library folder. I think might also be cool if there were drop zones in the preferences window, kind of like NSImageWell.
  4. I think this'll have enough content for its own section. Maybe just one called "Scripting".

I should have some time to also work on this in a couple weeks. I think it'd be a good addition.

thompsonate avatar Dec 01 '18 17:12 thompsonate

Hi all. I wrote about how I fixed issue in my blog: automatically change enable Dark Mode and dark iTerm, Vim profiles on sunset. No need to mess with AppleScript. You might find this useful.

apas avatar May 14 '19 09:05 apas