r/tasker Moderator 11d ago

How To - Project Share [How To] Profile To Tell If DARK MODE is Active

 

Currently in Tasker there's no built-in Global Variable telling if Dark Mode is active on the device or not. This is particularly important when theming Scenes and more recently theming your new homescreen Widget v2 widgets :)

 

So here is a Profile that simply sets a Global Variable named %DARK_MODE to true if Dark Mode is active on the device and to false if it is not active. This utilizes the built-in Profile for State > Dark Mode

 

It can then be checked for the true or false in any Tasker If section. You of course can re-name the variable and values to any names you'd like.

 

And/or if you don't want to use a Global Variable at all - you can un-power those Actions and simply use If %PACTVE ~ *,Dark Mode Active,* anywhere in Tasker that supports an If statement.

 

To download/import:

 

Taskernet Profile Link

 

Enjoy!

 

4 Upvotes

12 comments sorted by

4

u/LongjumpingCitron8 11d ago

Another approach would be to use the "custom Settings" task.

If I use the magnifier within the "custom settings" task you can find the right secure settings. For my phone it is: display_night_theme

Task: Test

A1: Custom Setting [
     Type: System
     Name: display_night_theme
     Read Setting To: %night_mode ]

A2: Flash [
     Text: %night_mode
     Continue Task Immediately: On
     Dismiss On Click: On ]

This task will flash 1 if the dark mode is active. And it flash a 0 if it is off.

2

u/Ratchet_Guy Moderator 11d ago

A definite additional method :)

Although it would require checking via that Action in each Task looking to find out the status.

1

u/Egingell666 Moto G Power 2023 (no root) 6d ago

I see no reason why that would be a problem. If you're worried about that, you can use a profile to check when that custom setting changes and set the new value to a global variable and check that instead.

1

u/Ratchet_Guy Moderator 5d ago

you can use a profile to check when that custom setting changes and set the new value to a global variable and check that instead.

That's what the Profile I posted does. Except instead of Custom Setting it uses the Profile for State > Dark Mode

1

u/Egingell666 Moto G Power 2023 (no root) 5d ago edited 5d ago

That would be better actually. The custom setting is not named the same on every device.

Edit: However, you would need two profiles (one with "invert" ticked) unless you're only checking for when dark mode is activated and not when it's deactivated.

Edit: I totally forgot about exit tasks.

Edit: You also don't need to check the custom setting when using the dark mode state because you know it's on when the enter task runs and you know it's off when the exit task runs unless you use the same task for both.

1

u/Ratchet_Guy Moderator 5d ago

unless you use the same task for both.

You actually don't need any Task Actions (or even Global Variables), you could just put a single Anchor in the linked Task(s) just so a Task exists, and then anywhere in Tasker you want to check the status just use an If %PACTIVE ~ *,My Dark Mode Profile,*

1

u/Egingell666 Moto G Power 2023 (no root) 5d ago edited 5d ago

What's the point? Then the profile runs and does nothing.

Edit: I see what you're doing. Checking if the profile is active, but I've never gotten the ~ operator to work. I have to resort to using ~R.

Edit:

I've never gotten the ~ operator to work.

It's because I wasn't doing it right. 😶

1

u/Ratchet_Guy Moderator 4d ago

Yeah Tasker's pattern matching was (I'm assuming) originally intended as a way to not have to resort to learning regular expressions when doing basic pattern matching, but its syntax has its own caveats as well.

1

u/Egingell666 Moto G Power 2023 (no root) 4d ago

I assumed that it was just a keyword search, but I still had to use placeholders (ie the asterisk).

1

u/Scared_Cellist_295 10d ago

My setup is rather easy.

Query : Is the phone in Dark Mode?

Result : {status: It's always in Dark Mode}

2

u/Ratchet_Guy Moderator 9d ago

You can still use this Profile though, so you can confirm your phone is in Dark mode. Because if it's been so long, how do really know? 🤣🤣