Vote Charlie!

Setting Mac app defaults by command line

Posted at age 28.

I had seen and run the defaults command many times on my Macs, usually in the course of following a tutorial to change some behavior Apple had removed the ability to easily modify. I never looked into the command much, but now that I did, I am glad I will be able to automate more of my setup!

I have been pulling together my dotfiles project, which involved my reviewing a lot of system setup instructions I recorded for myself in a Google Doc. Sometimes I wish I had done this years ago, but then I think of how caught up I can get in customizing and setting things up at the expense of actually doing anything, and I try to relax about it. My current motivation is partly practical, as my growing number of automated scripts and synchronization needs between my desktop and laptop require something more standardized and documented. I have definitely spent way more time than I should have generalizing the project to possibly be useful to others, though I have about zero expectation anyone else will ever look at it.

I have also been browsing other such projects. In @mathiasbynens/dotfiles, I saw a string of commands like this:

# Set up my preferred keyboard shortcuts
defaults write com.divisiblebyzero.Spectacle MakeLarger -data 62706c6973743030…

I finally looked at the documentation and then checked to see if this is how the window manager I use, Divvy, stores settings. I ran this command:

$ defaults domains | tr ',' '\n' | grep Divvy

That told me the “domain” is com.mizage.Divvy, so I then checked what settings were stored:

$ defaults read com.mizage.Divvy
    defaultColumnCount = 7;
    defaultRowCount = 6;
    lastColumnCount = 6;
    lastRowCount = 6;
    shortcuts = <62706c69 73743030 d4010203 04050847 48542474 6f705824 6f626a65 63747358 24766572 73696f6e 59246172 63686976 6572d106 0754726f 6f748001 a8090a12 2b2c333b 4355246e 756c6cd2 0b0c0d0e 5624636c 6173735a 4e532e6f 626a6563 74738007 a30f1011 80028005 8006dd13 14151617 18191a1b 1c1d1e0b 1f202122 23202425 26222829 2a5f1012 73656c65 6374696f 6e456e64 436f6c75 6d6e5f10 1173656c 65637469 6f6e5374 61727452 6f775c6b 6579436f 6d626f43 6f646557 656e6162 6c65645d 6b657943 6f6d626f 466c6167 735f1014 73656c65 6374696f 6e537461 7274436f 6c756d6e 5b73697a 65436f6c 756d6e73 5a737562 64697669 64656457 6e616d65 4b657956 676c6f62 616c5f10 0f73656c 65637469 6f6e456e 64526f77 5873697a 65526f77 73100110 00102909 12001000 00100708 80030910 05100680 0450d22d 2e2f3258 24636c61 73736573 5a24636c 6173736e 616d65a2 30315853 686f7274 63757458 4e534f62 6a656374 5853686f 72746375 74dd1314 15161718 191a1b1c 1d1e0b29 20342236 28242526 2228292a 10270912 00100000 08800309 8004dd13 14151617 18191a1b 1c1d1e0b 29203c22 3e202425 26222829 2a102509 12001000 00088003 098004d2 2d2e4445 a3454631 5e4e534d 75746162 6c654172 72617957 4e534172 72617912 000186a0 5f100f4e 534b6579 65644172 63686976 65720008 00110016 001f0028 00320035 003a003c 0045004b 00500057 00620064 0068006a 006c006e 0089009e 00b200bf 00c700d5 00ec00f8 0103010b 01120124 012d012f 01310133 01340139 013b013c 013e013f 01410143 01450146 014b0154 015f0162 016b0174 017d0198 019a019b 01a001a1 01a301a4 01a601c1 01c301c4 01c901ca 01cc01cd 01cf01d4 01d801e7 01ef01f4 00000000 00000201 00000000 00000049 00000000 00000000 00000000 00000206>;
    showMenuIcon = 0;
    useDefaultGrid = 1;

I figured I could then translate those to defaults write commands, though I noticed the -data flag in the other guy’s commands. The docs mention hexadecimal data, so I guessed I would use that flag with that shortcuts field that looks clearly like hex. Thus, I made a test using a fake domain:

defaults write com.mizage.Shivvy defaultColumnCount 7
defaults write com.mizage.Shivvy defaultRowCount 6
defaults write com.mizage.Shivvy lastColumnCount 6
defaults write com.mizage.Shivvy lastRowCount 6
defaults write com.mizage.Shivvy shortcuts -data 62706c6973743030d401020304050847485424746f7058246f626a65637473582476657273696f6e59246172636869766572d1060754726f6f748001a8090a122b2c333b4355246e756c6cd20b0c0d0e5624636c6173735a4e532e6f626a656374738007a30f1011800280058006dd131415161718191a1b1c1d1e0b1f20212223202425262228292a5f101273656c656374696f6e456e64436f6c756d6e5f101173656c656374696f6e5374617274526f775c6b6579436f6d626f436f646557656e61626c65645d6b6579436f6d626f466c6167735f101473656c656374696f6e5374617274436f6c756d6e5b73697a65436f6c756d6e735a73756264697669646564576e616d654b657956676c6f62616c5f100f73656c656374696f6e456e64526f775873697a65526f777310011000102909120010000010070880030910051006800450d22d2e2f325824636c61737365735a24636c6173736e616d65a230315853686f7274637574584e534f626a6563745853686f7274637574dd131415161718191a1b1c1d1e0b2920342236282425262228292a1027091200100000088003098004dd131415161718191a1b1c1d1e0b29203c223e202425262228292a1025091200100000088003098004d22d2e4445a34546315e4e534d757461626c654172726179574e53417272617912000186a05f100f4e534b657965644172636869766572000800110016001f002800320035003a003c0045004b00500057006200640068006a006c006e0089009e00b200bf00c700d500ec00f80103010b01120124012d012f0131013301340139013b013c013e013f0141014301450146014b0154015f0162016b0174017d0198019a019b01a001a101a301a401a601c101c301c401c901ca01cc01cd01cf01d401d801e701ef01f40000000000000201000000000000004900000000000000000000000000000206
defaults write com.mizage.Shivvy showMenuIcon 0
defaults write com.mizage.Shivvy useDefaultGrid 1

After running that, I read it back with defaults read com.mizage.Shivvy and confirmed the output was identical to defaults read com.mizage.Divvy. Woo!

Join the movement!

Show your support by signing up to be among the lucky few notified when I manage to blog. This could be as often as once a day or as infrequently as yearly!

blog comments powered by Disqus