Windows Script/Automation

So traditionally I do more bash/python scripting in Linux. However, I need to use Windows this school year for Autodesk Inventor and Adobe Lightroom.

I’ve messed up a few photo edits because I’ve had Windows Night Mode enabled. I would like help writing a script(powershell or otherwise) That would disable Night Mode when Lightroom is open and re-enable it when Lightroom closes.

Any help would be appreciated.

Powershell is the way I would go about it. Nothing outright built-in to powershell to manage night-shift, but I did find this blog post with a github link for a tool to manage it.

Once you have imported Set-BlueLight able to be run, the script is pretty much just…

Get-Process | % { if ($_.ProcessName -eq “Lightroom”) { Set-BlueLight -DisableBlueLight} else { Set-BlueLight -EnableBlueLight}}

The name of the executable without the file extension is what you need to have in the quotations, you may need to change it if I got that wrong.

Only thing I know of off the top of my head to get this running in the background is task scheduler, but there might be something better to use… it’s fairly basic, but it’s built in to Windows. This technet article is a pretty good guide on setting a powershell script as a scheduled task.

1 Like

Slight oversight in the script I posted. Need a break in the if statement, otherwise it’ll just turn night shift back on after it gets past Lightroom… Oops…

Get-Process | % { if ($_.ProcessName -eq “Lightroom”) { Set-BlueLight -DisableBlueLight; break} else { Set-BlueLight -EnableBlueLight}}

1 Like

Thanks @Jebedia47 I’ll definitely try this out tonight!

That’st the problem with needing all these futzy customizations.

I’ve learned to used the system without changes. I’m a lot more adaptable than some software.

Ok, I’m on break and I have time to code now. I’m having trouble importing the Set-BlueLight.ps1 file into PowerShell. I’ve looked through a bunch of sites and blogs and I’ve tried the Import-Module thingy.

Run powershell as admin and run Set-ExecutionPolicy RemoteSigned if you haven’t already.

There isn’t a command to import ps1 files outright, just call the .ps1 file at the beginning of your script.

Or change the file extension to .psm1 and add the Import-Module command to the beginning.

I prefer the former. Both methods make Set-BlueLight available per session.

1 Like

I was missing the Set-ExecutionPolicy RemoteSigned Thanks again!

Just a generic FYI.

Windows PowerShell is now effectively in end-of-life. All new effort will go into PowerShell Core. This is open source and can also be used on Linux/OSX. Whilst some of the commands/modules that currently run in PowerShell for Windows are not in PowerShell Core I’d recommend you start looking at that - expecially since any scripts you do generate there are likely to transferable to other OS’s in future.

1 Like