-3

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?

closed as unclear what you're asking by nohillside Sep 21 '17 at 11:53

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • BTW It's Dock not "doc". "Genie effect" is already the default. What do you mean by "and set the min/max value of the app icons to certain values", just what and where are you talking about!? When you say "how two remove the ⌘Space shortcut for spotlight search" are you talking about just turning off that shortcut or removing it completely from the system? BTW What version of OS X/macOS are you making theses changes under? The title of your question says, "Where is the reference to find out how to customize mac behaviour" and this is somewhat broad. – user3439894 Sep 21 '17 at 0:55
  • Almost everything you mentioned is a preference that can be changed in System Preferences. Now how to go about that, well you can either do it manually or automate it. Automating it can be done in a number of different ways. Everything you've mentioned can be manipulated within an AppleScript script, saved as as script or application. I'd save it as an application, place it in /Users/Shared and then when you login to a new user for the first time, navigate to it in Finder and execute it. As far as documentation is concerned, all official documentation is available at Apple's website. – user3439894 Sep 21 '17 at 0:55
  • all official documentation is available on apple's website.. can you give me the link please? – abbood Sep 21 '17 at 5:21
  • Can you answer the questions I've asked? – user3439894 Sep 21 '17 at 5:39
  • 1
    Please update your question then to focus on what you need. The only answer you got so far doesn't match your needs at all. – nohillside Sep 21 '17 at 11:53
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

Not the answer you're looking for? Browse other questions tagged .