Jump to content
paulminors

Change Alfred appearance with Apple Script

Recommended Posts

Hi, I have a simple workflow I’m to toggle the new Mac OS Mojave Dark Mode on and off.

 

  1. Create a new workflow with a keyword trigger e.g. “dark”.
  2. Set up an action to run an Apple Script:
tell application “System Events”
tell appearance preferences
    set dark mode to not dark mode
end tell
end tell
end alfred_script

 

However, what I’d like to do is customise the script to also toggle Aldred's appearance from "Alfred macOS" to "Alfred macOs Dark" if dark mode is enabled and then switch back to "Alfred macOS" when disabled.

 

And if anyone knows how I'd love to customise the script to toggle from the dynamic Mojave desktop to the dark version as well.

 

Any ideas on how I could do this?

Share this post


Link to post

Thanks for the response. However, I can't seem to get it to work. I downloaded the workflow, do I add this script to that workflow, or in a separate one? Here's my script but not sure what I'm doing wrong (I'm not great with Apple Script).

on alfred_script(q)
  tell application "System Events"

    tell appearance preferences

        set dark mode to not dark mode

    end tell

end tell

tell application "Alfred 3" to set theme "Alfred macOS Dark"

end tell
end alfred_script

 

Edited by paulminors

Share this post


Link to post

This works for me with one change -- you have an extra end tell in the 2nd to last line -- if your tell command is all on one line as in the line 

tell application "Alfred 3" to set theme "Alfred macOS Dark"

you don't use a separate end tell.

 

But it turns off dark mode while setting Alfred to a dark theme so you may want to reconsider aesthetically :)

 

You can use your script in its own workflow or edit the existing script in the workflow above to match -- I've modified my copy so much I don't remember exactly what the original script was.

Edited by dfay

Share this post


Link to post

But...the original relies on a command line call that may generate an error (it does in High Sierra):

 

    set guiMode to do shell script "defaults read -g AppleInterfaceStyle"

This is in a try command - if it works, the script knows the system is in dark mode -- if it throws an error, the script knows it's in light mode -- not the most graceful way to do it ...but I didn't write it and it's worked from Yosemite through High Sierra so far.  It may be the case that Mojave is setting a value for that default (and hence not giving an error) whether in light or dark mode in which case the approach would be to branch based on the value of guiMode.

Edited by dfay

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...