Is this the best way to start/stop/status filesharing for macOS ?
-- AppleScript to enable File Sharing on macOS
do shell script "sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist" with administrator privileges
do shell script "sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.AppleFileServer.plist" with administrator privileges
-- AppleScript to disable File Sharing on macOS
do shell script "sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.smbd.plist" with administrator privileges
do shell script "sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.AppleFileServer.plist" with administrator privileges
You should not use both ‘sudo’ and ‘with administrator privileges’ in one command.
Either one will do.
thanks for the response.
So the issue I’m getting is it seems like the toggle turns off then turns back on however, the service doesn’t seem to.
scenario1 - failed
check the file sharing window
file sharing toggle is on
close file sharing window
run unload commands
check the file sharing window
file sharing toggle is on
attempt to connect to the mac specific share
connection failed
scenario 2 - success
check the file sharing window
file sharing toggle is on
click the file sharing toggle off – manually
click the file sharing toggle on – manually
attempt to connect to the mac specific share
connection successful
so it seems the commands above aren’t doing what the manual clicking does. So how do I script it so it does do what the manual clicking does?
I have never used those commands, so can’t tell how they might go wrong. Sorry.
I’m not very confident in English, so I might be misunderstanding something (apologies if that’s the case!).
I’m using macOS 15, so com.apple.AppleFileServer is no longer configurable
this is just about SMB file sharing.
Just wanted to share a quick note about enabling/disabling file sharing (SMB) on macOS.
Behavior can vary a bit depending on the OS version.
In earlier versions of macOS
I used to disable file sharing like this:
/usr/bin/sudo /bin/launchctl unload -w /System/Library/LaunchDaemons/com.apple.smbd.plist
/usr/bin/sudo /bin/launchctl disable system/com.apple.smbd
Starting with macOS 14, I now do it this way:
/usr/bin/sudo /bin/launchctl bootout system/com.apple.smbd
/usr/bin/sudo /bin/launchctl disable system/com.apple.smbd
And when I want to start file sharing again on macOS 14 or later, I use:
/usr/bin/sudo /bin/launchctl enable system/com.apple.smbd
/usr/bin/sudo /bin/launchctl bootstrap system /System/Library/LaunchDaemons/com.apple.smbd.plist
I’m not entirely sure if this method is the “correct” one, but it works for me on macOS 14 and later. If mentions their macOS version, there might be someone who can offer a more optimized solution for their setup.
Hope this helps!
Interesting… I figured the sudo was for the shell and the administrator privileges was for AppleScript.