Toggle Wallpaper based on VPN Connection

Working from home on a MacMini, I use work-provided VPN to connect to certain applications at the office. Otherwise, I don’t need/use that VPN. But I always forget to disconnect it.

I’d like to automate, applescript, or kludge together a visual reminder.

When I connect to workVPN, set my desktop background to solid red. When I disconnect from workVPN, restore the default wallpaper.

Any suggestions where to start? Best tool to use?

Thanks.

Glad you brought this up, as it’s something I’ve been meaning to do.
I have a keyboard maestro action that enables or disables my VPN. I just added a Set Desktop Image action for the connect and disconnect sections.
It’s kind of weird, but the way to set the desktop color is to set the desktop image to a transparent .png file, with the Fit to screen option. That will allow you to set a background color, which then fills the screen. ref

This is all specific to my client (Cisco AnyConnect), but it might get you started if you want to go this route.

Caveat emptor, of course.

1 Like

I use TextBar to put a note in the menu bar when I’m connected to my VPN. I might not notice my desktop image changed.

3 Likes

@JohnAtl Very generous of you. Thanks so much. I’ll experiment and adapt to my VPN.

@tjluoma Good idea, TJ. I never seem to notice the icon in the menubar; text might be better, but red is my trigger :slight_smile:

TJ are you using a script to show VPN status in textbar?

Yup. I’m using Encrypt.me for my VPN which lets me check its status via AppleScript.

Other VPN apps which use standard VPN tools in macOS should be identifiable using something like this:

scutil --nc list | fgrep -q '(Connected)'

if [ "$EXIT" = "0" ]
then

	echo "VPN Connected"

else

	echo "VPN Disconnected"

fi

However, I know that VPNUnlimited used to work with scutil but does not any more, so other VPNs might not either. If that’s the case you’d have to ask them if they have a scriptable way to check if the VPN is active or not.

Of course you could check to see if a specific VPN app is running or not, but that doesn’t really tell you if the VPN connection is active so I do not recommend that.

1 Like

You could, of course, make the text red using TextBar.

Go to the “Colored Text” header on TextBar’s GitHub page for an example.

n.b. I believe that feature was added (or at least clarified) after Katie Floyd asked about it when I was on Mac Power Users #321 and talked about TextBar back in 2016.

(Aside: May 2016 feels like approximately 20 years ago.)

Thanks for all the good ideas @tjluoma.
My VPN is GlobalProtect – it works, but is extremely thin on features :smile: