A programmatic method for disabling all sharing services?

I'm looking for a programmatic method for disabling all the sharing solutions on a Mac. My choice is for an AppleScript or a shell script.

I would certainly such as to have actually the solutions received the image listed below impaired when I execute the script. The remedy needs to work with Alfred, Keyboard Maestro or any kind of various other international performance device.

The solutions I would certainly such as to disable are:

I can think of the adhering to with some googling:

File sharing (on/off)

do shell script "/usr/sbin/AppleFileServer" password "x" with administrator privileges
do shell script "/usr/bin/killall AppleFileServer" password "x" with administrator privileges

Internet Sharing (on/off)

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.InternetSharing.plist        

( I would certainly favor incurable commands or set manuscripts to apple manuscripts . Below is an apple script solution for those interested.)

2022-06-07 14:30:27
Source Share
Answers: 2

Here is a covering script that switches off the solutions, yet I'm working with locating an extra straight remedy:

osascript << HERE
tell application "System Preferences" to activate
tell application "System Events" to tell process "System Preferences"
    click menu item "Sharing" of menu "View" of menu bar 1
    delay 2
    tell window "Sharing" to repeat with x from 1 to 11
        if value of checkbox 1 of row x of table 1 of scroll area 1 of group 1 is 1 then click checkbox 1 of row x of table 1 of scroll area 1 of group 1
    end repeat
end tell
tell application "System Preferences" to quit
2022-06-07 16:30:17

Don't neglect you can merely execute your AppleScript at the command - line making use of the osascript device as opposed to installing it <<EOF design within the script as Daniel suggests.

That suggests you can recycle the script you recognize currently collaborates with a one line shell script:

osascript ChangeSettings.scpt

(thinking ChangeSettings.scpt is the documents in the existing functioning directory site having the AppleScript you stated)

2022-06-07 16:10:37