Need Help with building a script to Turn on Screen/File Sharing at login

Hello, This is my 1st post here. I have an issue in 10.15.7 that I can not fix. Screen sharing and file sharing work as expected, once they are turned on. Although, after a boot, or a restart these are both unchecked. I'm at a lost to how to fix, so I wrote a KM script to turn on Screen and File Sharing at login.

It's a simple script, but will only run one time after building it and will not run a second time. Curious what I am missing? I open "Sharing" that works all the time. Then, this is were it stops ... I need to hit "tab" 3 times to get to Screen share, then "space" to toggle it on, then, the down arrow, then "space" to turn on File sharing. I can easily do this pattern with my keyboard, but KM gets caught on something? Many thanks for any thoughts. Best, Brad

Welcome, cradbobb!

System can be a tricky beast to automate. It can usually be done with AppleScript, but the language is very finicky. I don't know exactly how to do that, although others here might.

Another Way?

I have a couple of ideas that might fix the underlying issues without using Keyboard Maestro.

  1. Have you tried using "Remote Management" instead of screen sharing:

When you first check the box, you can turn on/off these options. I just leave them all on:

That should work, but given that your system is acting strangely, obviously it might not. If it does, it might solve the screen sharing problem.

  1. Can you manually enable file sharing after a reboot?

To check, enter this line in, and then enter your login password when prompted:

sudo launchctl load -w /System/Library/LaunchDaemons/

Note: if this is the first time you have used sudo you will get a big scary warning message, which you can mostly ignore.

If that works, we could automate running that command after a reboot, rather than trying to do it with Keyboard Maestro and System Preferences.

Hi Brad.

When KM is “typing” keystrokes it often does it faster than MacOS can keep up with so often the solution to this kind of issue is to insert some Pause actions to give your Mac an opportunity to catch up, so to speak.

It would be really helpful if you could upload your macro (both as a file and an image) so we can properly see what’s going on and also test it for ourselves. That way removes a lot of the guesswork!

Thanks tjluoma, I did try Remote Management and it will also turn off on a reboot, or start.
I can manually turn these functions on, but, these are for headless cpus, which makes it all more cumbersome. BTW: All testing has been on cpus with monitors. I've been working on this for a few days, I did try the sudo command, both manually and with KM, but then found out "yesterday" that sharing can not be enabled from the terminal 10.14 on... at least that was the prompt I got. Odd that I never got that message at the beginning for these commands.

tiffle, Thanks I did try different pauses, not nothing worked. Once I upload, this will the basic script with no pauses. At this point I hope I just missed something and can move on :wink:

Here's what i have so far, thanks!

Hi Brad - since macros could be malicious, you'll find people here are more comfortable to download your macro once they've seen it here on the forum, which is why I suggested posting it as both an image and a file.

Have a look here about how to do that: Forum [Keyboard Maestro Wiki]

I'm not saying yours is - I just want you to get the best response!

Ah, of course, I was not thinking in those terms. Great info on the upload, I missed that concept. Thanks for all the help.

turn on screen sharing Macro (v9.2)

turn on screen sharing.kmmacros (3.6 KB)

Hi Brad.

I had a look at your macro and I couldn't get it to work so I've written a short macro that uses AppleScript to enable Screen and File sharing.

Here's the macro:

and the code:
turn on screen-file sharing.kmmacros (3 KB)

If sharing is already on then this macro will leave it as is, otherwise it'll turn them on. Finally, it closes the preference pane.

Tested on Mojave. Hope that helps.

Wow... Tadeusz,

You are incredibly cool to do that. Thanks!

It partly works on 10.15.7 it only turns on File sharing.

If I could choose, I would rather the Screen-Share to get into the CPU to do what I need.

Happy to pay, if you have the time.

Never used AppleScript, so I'm out of my league. Many Thanks!

Oh Brad - like I said I’m on 10.14 so the problem is my Preference Pane is different to yours.

Can you post a screenshot of your Preference Pane so I can know for sure what edits I need to make?

Once you do that I’ll re-post the macro for you - no strings attached! Two-minute job once I’m back at my desk.


Tadeusz, Very Kind of you. How great, I will be back at my shop tomorrow and will post that image. Thanks, Brad

If your Preference Pane looks like the one tjluoma posted above then this new version of the macro should do the job:

turn on screen-file sharing (MacOS 10.15).kmmacros (3.0 KB)

Just so you know - if you have any coding experience you'll see that the only difference is the use of row 1 and row 2 in the new version as opposed to row 2 and row 3 respectively in the previous version.

Here's my Preference Pane where I've highlighted the settings of interest:
KM 1 2021-08-20_11-32-48

So if you want to tweak stuff, you have a head start!

Exactly, thanks for that, my "sharing pane" does look like the one in tjluoma's post. I will be able to test in the next hour. And good info on the the script, it does make sense to me. Brad

1 Like

Thank you Tadeusz, This script works every time! You have allowed me to move on from this impasse, thanks for that. It would be hard for me to work without screen-share functionality. My hunch is that it was botched on the last 10.15.7 "security update" but of course not certain. Have a great weekend, and many thanks. Best, Brad

1 Like

Cheers Brad - you have a good one too!

Thank you to all the folks who helped @cradbobb - Brad had emailed me late last week but I was busy volunteering at a robotic competition and had just enough time to suggest the forum might help before I could get another look at the problem.

Thank you all for proving once again that this really is the best forum on the Internet!