how to create a dot file for default mac settings

Background

I have a habit of creating new user profiles on my mac that serves different needs (ie recruiting, software development etc). I'm always thinking of ways to make creating a new user less expensive, one is saving all sorts of setting files and saving them in dropbox (ie alfred settings, slate settings, bash_profile, vimrc etc etc).

I also have many settings that I have to issue mac commands for (like this one):

defaults write com.apple.screencapture location ~/Documents/Screenshots   
killall SystemUIServer

How can I save these in a "dot file", and simply have the system read them on load (ie like ~/.bash_profile)?


Solution 1:

  • create a bash script for all the config commands, e.g.

    #!/bin/bash
    
    defaults write com.apple.screencapture location ~/Documents/Screenshots   
    killall SystemUIServer
    
  • store it in /usr/local/bin under whatever name you like

  • run it once for each new account

Solution 2:

The easiest thing is probably to create an app bundle that executes any number of arbitrary things, then add it to your login items under System Preferences -> Users and Groups -> Login Items.

enter image description here

I'd recommend using AppleScript to do be the middleman. Create a new Applescript to run your task, then go to File -> Export... and choose Application.

enter image description here

Alternatively you can just add it to your ~/.bash_profile if you'd like. There's a possibility this isn't configure to run on startup because macOS; if that's the case, just add it to your ~/.bashrc.