Jump to content

Change Alfred theme programmatically


Recommended Posts

Hi there,

 

I'm Mauricio and new to this forum :) I like to program in my spare time and have just reviewed the change log of v2.6 which includes

  • Ability to set theme UID externally via AppleScript

And I want to know how to do this exactly, where can I find more information about this?

 

My goal is to switch themes when f.lux enables the Dark Theme of OS X at sunset (or in reverse of course).

 

Would love to hear any ideas on this.

 

Cheers! 

Link to comment

Hi there,

 

I'm Mauricio and new to this forum :) I like to program in my spare time and have just reviewed the change log of v2.6 which includes

  • Ability to set theme UID externally via AppleScript

And I want to know how to do this exactly, where can I find more information about this?

 

My goal is to switch themes when f.lux enables the Dark Theme of OS X at sunset (or in reverse of course).

 

Would love to hear any ideas on this.

 

Cheers! 

 

Here you go...

 

http://www.alfredforum.com/topic/5138-change-the-alfred-theme-within-a-workflow/#entry31375

 

In OS X's Script Editor, you can open Alfred's AppleScript dictionary which tells you Alfred's AppleScript methods :)

 

Cheers,

Andrew

Link to comment

This AppleScript will change Alfred's theme based on whether dark mode is on or off, but I haven't figured out a way to trigger it automatically when dark mode is toggled. You might have to use a Launch Agent to run it every 5 minutes or so (or grab a list of sunset times for your location from somewhere).
 

tell application "System Events"
	tell appearance preferences to set dark mode to false
	if (dark mode of appearance preferences) then
		tell application "Alfred 2" to set theme "Dark"
	else
		tell application "Alfred 2" to set theme "Light"
	end if
end tell
Link to comment

I really like the idea of toggling Alfred's theme, so I've written a Python script that will change your theme to/from dark at sunset/sunrise. It isn't possible to hook into f.lux directly (or OS X's dark mode), but I think this is a reasonable solution.
 
It creates a Launch Agent that will call the script at sunrise and sunset every day to change the theme to/from dark/light.
 
I'm looking into turning it into a workflow, but that will probably depend on being able to find an API that will let me look up latitude, longitude, elevation and timezone for a given location.
 
Note: Seeing as I just wrote the script, it obviously hasn't been tested across several sunrise/sunset cycles. It also requires the astral and pytz libraries.

 

Get the script here.

Edited by deanishe
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...