You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

How can I automate my VNC connection on Mac mini?

Hey all. Due to some problems maintaining a stable bluetooth connection between my Cambridge Audio amplifier and M2 Mac Mini, I'm forced to connect them via USB and this means running the mac mini headless.


This causes lots of connecting to the mac mini every time I want to stop/start/adjust music as I generally don't stay connected due to changing VPN connections. I use Apple's built-in VNC connection (apple-k at the desktop) but this involves selecting the correct vnc server (I have a couple), approving username/password and then selecting connection quality.


I'd prefer to be able to have an icon in the taskbar that I just clicked and it would run through these steps and open the vnc window. Just wondering how to do this ... I don't think I could do this purely through a link, the other options I can think of would a bash/zsh script or an applescript. Has anyone tried this and got it working?



[Re-Titled by Moderator]

Mac mini, macOS 15.2

Posted on Jan 4, 2025 7:11 AM

Reply
6 replies

Jan 4, 2025 1:00 PM in response to Mac@DBB

Mac@DBB wrote:

Because the bluetooth connection is very unstable (the amp only supports bluetooth up to 14.2) and that leaves me with only USB as an option as there is no room for a monitor and a mac mini in the location where the amp is positioned.

Sounds like a problem that could be solved with some longer cables.

I use a VPN for work and need to connect to multiple different sites each with its own VPN.

Fair enough. I just have to ask these days because so many people have fallen for the many "security" scams out there.

A little more detail on this part of the answer might be helpful. I guess now I know its possible I'll search more - initial searches said it wasn't possible.

Just the standard "Save Password" button:

But now that I look at it again, if you launch from a standalone file, you still get the dialog. The details are already filled, but you still have to click "Sign In".


Another option is to just launch Screen Saver by itself. It remembers all of your previous connections. You can just pick the desired connection from the list. You can specify the login and resolution type for each. In this interface, you don't have to click any additional dialogs at all.


The only problem here is that you do have to start Screen Saver first. I couldn't find any shortcut to make Screen Saver automatically connect. I tried recording with Automator. That a really crude solution, but it seemed to work. Once you have a workflow, you can save that as an app, service, or just about anything.


It might be possible to use a 3rd party app. There are a couple of things to be concerned about. Supposedly, Apple Screen Sharing is compatible with VNC. But I'm not sure it's really VNC. I've had very poor experience with actual VNC clients and servers. I've seen some apps that maintain front-ends and then connect via native Screen Sharing. But it's been a few years since I tried that. I just download a new copy of the app I used to use and it saved my password in plain text. So I'm not going to recommend that one.


My recommendation would be to just add Screen Saver to Login Items or something. Then launch the connection from the Screen Saver interface. That way, everything is saved, streamlined, and secure.

Jan 4, 2025 7:33 AM in response to Mac@DBB

Mac@DBB wrote:

Hey all. Due to some problems maintaining a stable bluetooth connection between my Cambridge Audio amplifier and M2 Mac Mini, I'm forced to connect them via USB and this means running the mac mini headless.

Why?


This causes lots of connecting to the mac mini every time I want to stop/start/adjust music as I generally don't stay connected due to changing VPN connections.

Why are you using a VPN?


I use Apple's built-in VNC connection (apple-k at the desktop) but this involves selecting the correct vnc server (I have a couple), approving username/password and then selecting connection quality.

I'd prefer to be able to have an icon in the taskbar that I just clicked and it would run through these steps and open the vnc window.

I'm not sure what you mean by "taskbar". There is no such thing on a Mac. You could be talking about a number of different artifacts.


I can tell you that you can save your name and password. And then, after connecting once, you can save your connection to a file. Double-click that file to open the connection. It won't prompt you to choose a quality after that. Hopefully you can integrate that file into your "taskbar" using standard methods.

Jan 4, 2025 7:48 AM in response to etresoft

etresoft replied:


>Why?


Because the bluetooth connection is very unstable (the amp only supports bluetooth up to 14.2) and that leaves me with only USB as an option as there is no room for a monitor and a mac mini in the location where the amp is positioned.


>Why are you using a VPN?


I use a VPN for work and need to connect to multiple different sites each with its own VPN.


> I'm not sure what you mean by "taskbar". There is no such thing on a Mac. You could be talking about a number of different artifacts.


Artifacts??


"dock". Working with MacOS, Linux and Windows, easy to use the wrong term.


>I can tell you that you can save your name and password.


A little more detail on this part of the answer might be helpful. I guess now I know its possible I'll search more - initial searches said it wasn't possible.



Jan 4, 2025 8:59 AM in response to Mac@DBB

To answer my own question here, following the note from etreSoft.


Open the vnc connection as usual using apple-k from the desktop (or the Screen Sharing app). When logged in, go to the connection menu and select "save as". This allows saving the session information as an XML vncloc file. But opening this will still prompt for the username/password confirmation, so edit the vncloc file in something like TextEdit or BBedit and change the line:


<string>vnc://10.0.0.131?quality=adaptive&amp;numVirtualDisplays=0</string>


to


<string>vnc://Username:Password@10.0.0.131?quality=adaptive&amp;numVirtualDisplays=0</string>


where 10.0.0.131 should match the address of the VNC server, and Username/Password are the username and password for the server (note apple's suggestions on picking a safe vnc username).


With this change made, the file can be dragged into the dock and clicking it will open the vnc session without prompts.

Jan 4, 2025 2:06 PM in response to Mac@DBB

Mac@DBB wrote:

I did find a working solution using your idea as a starter, its further up this thread

Yes. I saw that. This forum has a funky default sort order. It's infuriating.


I just hate seeing passwords hard-coded in plain text like that. That will give you problems at some point in the future. Same with remote connections. It will fail, probably when you are the most busy with something else. At a minimum, I recommend replacing it with a Bonjour address. For example, here's the URL from one of my test vncloc files:


vnc://Administrator%E2%80%99s%20Virtual%20Machine._rfb._tcp.local?quality=full&amp;numVirtualDisplays=0


This will always work, even if the device gets restarted and comes up with a different IP address.


But yes, the longer cables weren't going to really work in the setting.

I understand. I just like elegant solutions.


How can I automate my VNC connection on Mac mini?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.