如何通过脚本打开 "File and Folder sharing with SMB"

How to turn on "File and Folder sharing with SMB" via script

在我工作的公司中,我们正试图允许在所有 mac 上共享文件,以便我和我的 IT 团队能够远程查看他们的文件。但是我对mac不是很熟悉。有没有办法编写这个过程的脚本,最好是在 Python 中? (如果不是python,那么applescript)

谷歌搜索,在我看来,您可以使用这组命令行为文件夹打开 SMB 文件共享,您可以根据需要从 Python 或 AppleScript 运行 或 AppleScript :

sudo /usr/sbin/sharing -a /path/to/sharedFolder
sudo /usr/sbin/sharing -e sharedFolder -s 001
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist

第一行创建共享记录,第二行添加SMB标志到记录,第三行启动文件服务器。

site where I saw the last command 有第二个命令:

sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server.plist EnabledServices -array disk

我不知道这条线到底做了什么——如果有的话——虽然它可以确保 SMB 在重启后重新启动(?)

N.B.: 我不确定共享命令行工具是什么时候添加到系统中的。它可能是最新的,因此如果您使用的是 运行 较旧的系统,则应检查以确保它可用。有关示例和选项,请参阅 man sharing