Where is the reference to find out how to customize mac behaviour [closed]

Background

This question asks how to programmatically change the cursor size. I actually have a long list of items I would like to customize every time I create a new user on mac, and I'm not sure where to find the reference for each (ie in order to change them programmatically)

I have macos sierra version 10.12.6

the list includes:

  • making the mouse not scroll naturally
  • make the doc automatically hide
  • set the min/max value of the app icons to certain values as depicted here: enter image description here

  • remove all the default app icons form the doc as depicted here enter image description here

  • how two remove the Space shortcut for spotlight search as depicted here: enter image description here

  • etc

Question

Can someone please show me where I can find an official reference online where I can find out where I can program such things?


Solution 1:

If you're wanting to use AppleScript to automate changing a set of system preferences, then the AppleScript Language Guide is where to start learning how to use AppleScript.

As far as "a reference list of scriptable configuration items" you mentioned in your comments, to my knowledge, there is no unified reference list of items in System Preferences that can be configured using AppleScript UI Scripting. The list, per se, is right in front of you, it's the entire System Preferences UI itself and the querying of the UI via System Events and UI elements to get the object properties and their hierarchy.

Examples:

tell application "System Events" to get every UI element of window 1 of application process "System Preferences"
tell application "System Events" to get properties of every UI element of window 1 of application process "System Preferences"
tell application "System Events" to get every UI element of scroll area 1 of window 1 of application process "System Preferences"
tell application "System Events" to get properties of every UI element of scroll area 1 of window 1 of application process "System Preferences"

If you have Xcode installed, you can use Accessibility Inspector to get information about the UI elements and their hierarchy.

Any application process that has its has scripting terminology property set to true should have an AppleScript Dictionary that you can open from Script Editor > Window > Library and then peruse to see what's available to directly script with that given application.

With a given app running if you run the following command in Script Editor, e.g.

tell application "System Events" to get has scripting terminology of process "System Preferences"

It returns true, however in the case of "System Preferences" there is a small set of commands you can use directly with it, however to make some of the setting changes you mention in your OP, using AppleScript, you need to use UI Scripting.

As you can see by the example AppleScript code below, it in most part uses UI Scripting but does so without having to have the System Preferences UI visible. The primary issue with UI Scripting can be adding appropriate delay commands as needed in some places. This come with experience but also with necessity when you run a script, e.g. in Script Editor, and it errors out. Inserting the delay and appropriate value for it becomes second nature with time at programming UI Scripting.

Here is some example AppleScript code, you might find useful to help achieve your goal of automating setting for a new user.

Note that while this worked on my system running macOS 10.12.5 as is and without issue, YMMY and some adjustments may need to be made and or additional error handling, etc.

tell application "System Preferences"
    if running then
        quit
        delay 0.5
    end if

    --  # General

    reveal pane id "com.apple.preference.general"
    delay 0.5
    tell application "System Events"
        --  # Automatically hide and show the menu bar
        click checkbox 4 of window 1 of application process "System Preferences"
    end tell

    --  # Dock

    reveal pane id "com.apple.preference.dock"
    delay 0.5
    tell application "System Events"
        --  # Size (Valid values, 0.0 to 1.0)
        set value of value indicator 1 of slider 1 of window 1 of application process "System Preferences" to 0.25
        --  #   Magnification
        if value of checkbox "Magnification:" of window 1 of application process "System Preferences" is equal to 0 then
            click checkbox "Magnification:" of window 1 of application process "System Preferences"
        end if
        --  # Min Max (Valid values, 0.0 to 1.0)
        set value of value indicator 1 of slider 2 of window 1 of application process "System Preferences" to 1.0
        --  # Automatically hide and show the Dock
        click checkbox 2 of window 1 of application process "System Preferences"
    end tell

    tell current application

        --  # Backup the original com.apple.dock.plist file before removing all default apps from the Dock.

        do shell script "cp -a $HOME/Library/Preferences/com.apple.dock.plist $HOME/Library/Preferences/com.apple.dock.ORIGINAL.plist"

        --  # Remove all default apps from the Dock. This removes everything but Finder and Trash, neither of which can be removed.     

        do shell script "defaults delete com.apple.dock persistent-apps; defaults delete com.apple.dock persistent-others; killall Dock"

        --  # To restore the default Dock Tiles, use the following command. 
        -- do shell script "defaults delete com.apple.dock; killall Dock"

    end tell

    --  # The following commented code, between '(*' and '*)' directly manipulates the included Dock preferences.
    --  # This is a more direct way then using the UI Scripting method on the Dock preferences above.
    --  # See the System Events AppleScript Dictionary.

    (*
    tell application "System Events"
        tell dock preferences
            set minimize effect to genie
            set magnification size to 1.0
            set dock size to 0.5
            set autohide to true
            set animate to true
            set magnification to true
            set screen edge to bottom
        end tell
    end tell
    *)

    --  # Keyboard > Shortcuts

    reveal anchor "shortcutsTab" of pane id "com.apple.preference.keyboard"
    delay 0.5
    tell application "System Events"
        --  # Spotlight
        select row 7 of table 1 of scroll area 1 of splitter group 1 of tab group 1 of window 1 of application process "System Preferences"
        --  # Show Spotlight Search
        click checkbox 1 of UI element 1 of row 1 of outline 1 of scroll area 2 of splitter group 1 of tab group 1 of window 1 of application process "System Preferences"
    end tell

    --  # Mouse

    reveal pane id "com.apple.preference.mouse"
    delay 0.5
    tell application "System Events"
        try
            --  # Apple Magic Mouse
            --  # Point & Click
            click radio button 1 of tab group 1 of window 1 of application process "System Preferences"
            --  # Scroll direction: Natural
            click checkbox 1 of tab group 1 of window 1 of application process "System Preferences"
        end try
        try
            --  # Generic Mouse
            --  # Scroll direction: Natural
            click checkbox 1 of window 1 of application process "System Preferences"
        end try
    end tell
    quit
end tell

--  # Notify the User, changes have been made.

tell current application
    display dialog "The custom settings have been applied." buttons {"OK"} default button 1 with icon note
end tell