Weblog

  • Tower Watch Python Script

    I’ve been keeping an eye on the ‘Cellular for Nova Scotia Program’, which is a government-funded initiative to upgrade cell towers all across the province in order to bolster cellular connectivity. It’s a highly-essential project that I’ve been watching for a few years now.

    Progress has been a bit slow lately, and I’ve even noticed a few errors with updates to the progress pages. For example, a tower upgrade that is now complete has not been tagged as such. Rather, its smaller, less-visible ‘In service’ tag is now displayed in place of its previous ‘Underway’ status tag.

    I’ve been in the habit of checking my area’s page almost every day to see if my local tower has had its upgrades completed, or its deadline pushed back. It’s frustrating checking a page everyday eagerly waiting for a sign of news, only to be met with what seems like a dead page. An intern’s job for later.

    So, I was consulting with Claude AI, and I had it devise me a python script, which runs in a virtual environment, that parses the webpage every morning, and check the status of my local tower. It compares the status string to its previous value, and once there is a change detected (hopefully not too far off in the future) it will send me a notification to my phone.

    The notification is handled by sending a POST request to a ntfy topic that I’ve set up specifically for this purpose.

    ntfy is an application, available on web, iOS and Android, that allows you to send push notifications for nearly anything you want. You can also send messages with it sort of like texting. The only downside is you need to create a topic for the notification channel. The topic name has to be unique and obscure, because if anyone guesses it, they can read all your notifications.

    I elected to use a random string of base64 as the topic name for this purpose. I would recommend anyone do the same for sensitive notification channels.

    At the end of the day, there will only be one notification sent to this channel, and that will be on the day there is a status update for the cell tower in my region. Then, the script will have served its purpose, and will no longer be needed.

    I have also used ntfy for another purpose, which is much larger in scope than this small python script. I will share that project here soon, and hopefully you will enjoy reading it as much as you did reading about this one!

  • Change Windows 11 Theme with PowerShell

    This PowerShell script can be used to swap between a user-created dark and light theme

    I’ve been running Debian and Arch Linux on a couple of my desktop PCs, and I am very pleased with the performance of Debian with GNOME 50, and Arch with the same. I also run Debian with KDE Plasma which is also fantastic.

    I use Windows 11 for my musical DAW software, which depends upon it. It’s not available for Linux (yet). However, I noticed something particularly annoying: there wasn’t a simple user toggle switch for something as simple as dark/light mode for the Windows 11 desktop environment. I was frustrated by this. Having to open the Settings app, select Personalization, then Themes, then to pick the dark or light theme.

    I had customized my themes to remove that ugly wallpaper that ships with Windows 11 (it looks like a mushroom or something that would grow on the side of a tree in the forest). A nice retro blue color for light mode, and a plain black background color for dark mode.

    So I consulted with Claude Opus 4.7 which came up with this PowerShell script that can detect and immediately toggle between themes. There are some caveats though:

    With dual monitors, the script causes a glitch: the taskbars on the dual monitors sometimes become out of sync theme-wise, and sometimes their fonts do the same. If you run a dual monitor setup I recommend disabling the taskbar on the secondary monitor.

    Important: Make sure you create and save a custom light theme and dark theme from within the Settings app, as they will save to your AppData\Local\Microsoft\Windows\Themes\ directory. Replace ‘MyDarkTheme.theme‘ and ‘MyLightTheme.theme‘ in the script below for them to take effect.

    # switch.ps1
    # Toggles between two saved Windows themes based on current AppsUseLightTheme value.
    
    $darkTheme  = "$env:LOCALAPPDATA\Microsoft\Windows\Themes\MyDarkTheme.theme"
    $lightTheme = "$env:LOCALAPPDATA\Microsoft\Windows\Themes\MyLightTheme.theme"
    
    # Read current mode (0 = dark, 1 = light)
    $key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize'
    $isLight = (Get-ItemProperty -Path $key -Name AppsUseLightTheme).AppsUseLightTheme
    
    # Pick the opposite
    $target = if ($isLight -eq 1) { $darkTheme } else { $lightTheme }
    
    if (-not (Test-Path $target)) {
        Write-Error "Theme file not found: $target"
        exit 1
    }
    
    # Apply theme. This opens Settings momentarily — we close it after.
    Start-Process -FilePath $target
    
    # Give Windows a moment to apply
    Start-Sleep -Milliseconds 1500
    
    # Close the Settings window that pops up
    Get-Process -Name "SystemSettings" -ErrorAction SilentlyContinue | Stop-Process -Force

    You need to save the script as a .ps1 file, then you can run it by double-clicking it, or, you can create a shortcut to the script, and give it a keyboard shortcut to launch it. I chose the F9 key.

    Important: If you create a shortcut to the PowerShell script, you may need to edit the shortcut target to be the following. Be sure to edit the user name in the file path:

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -File "C:\Users\your_user_here\Desktop\switch.ps1"

    It works, but it’s a bit wonky admittedly. But this is the solution I went with, and will continue to use going forward. Please let us know if it works for you and you’re happy.

  • Just getting started!

    Thanks for visiting DURPANET! I’m trying to get a computer and technology collective going. Just people who share a passion for all sorts of technology old and new.

    We’re based out of Pictou County, Nova Scotia and are always looking to grow! Come say hi!