Add a Recent or Favorites Folder to Your Dock Using the macOS Terminal


Type the query add recents dock terminal into any Internet search engine and most – if not all – relevant entries on the first results page will give the following code or a slight variation of it:

defaults write persistent-others -array-add '{"tile-data" = {"list-type" = 1;}; "tile-type" = "recents-tile";}'; killall Dock



Most of these articles are from 2015 or earlier and the Mac OS has changed a lot since, but the code still appears to do exactly as advertised.

However, I’m certain this has been true with earlier releases of OS X and macOS and now continuing with High Sierra the code only ever creates a Recent Applications stack whose content is always displayed as a Fan. If you want Recent Documents, Recent Servers, Favorite Volumes or Favorite Items displayed as a Grid or List you have to manually amend the newly created Dock stack by right-clicking it.

No big deal. But if you want to create any one of the aforementioned stacks displayed in any one of three possible ways from the command line, try this:

defaults write persistent-others -array-add '<dict><key>tile-data</key><dict><key>list-type</key><integer>1</integer><key>preferreditemsize</key><integer>-1</integer><key>viewas</key><integer>2</integer></dict><key>tile-type</key><string>recents-tile</string></dict>'; killall Dock



Let’s format that lengthy string passed to the defaults command so it’s easier to read:




The string contains a number of key/value pairs. The two of interest are the key list-type and its integer value 1 and the key viewas and its integer value 2. The integer value for the key list-type determines the type of stack:

Key/Valuestack Type
<key>list-type</key><integer>1</integer>Recent Applications
<key>list-type</key><integer>2</integer>Recent Documents
<key>list-type</key><integer>3</integer>Recent Servers
<key>list-type</key><integer>4</integer>Favorite Volumes
<key>list-type</key><integer>5</integer>Favorite Servers



The integer value for the key viewas determines how the contents of the stack are displayed:




So, is there something wrong with the original code that’s been doing the rounds since as far back as 2011? As there’s no viewas key/value pair we can’t expect it to determine how the stack is displayed, but even if there were it still wouldn’t work. The following code creates a Recent Applications stack displayed as a Fan even though list-type is set to 3 and viewas is set to 2.

defaults write persistent-others -array-add '{"tile-data" = {"list-type" = 3; "viewas" = 2;}; "tile-type" = "recents-tile";}'; killall Dock 



The reason being is, this code causes the values for the keys list-type and viewas to be stored as string data types, whereas they need to be stored as integer data types and <integer>1</integer> does exactly this. The process responsible for building the Dock appears to be ignoring these numbers stored as string data types and defaulting to a Recent Applications stack displayed as a Fan.

You may have also noticed the use of another key/value pair: preferreditemsize</key><integer>-1</integer>. When displayed as a grid, this value determines the icon size. A value of -1 appears to be the default size. 0 is the smallest and 3 is about the same size as the default.

Recent Applications stack on 2727" iMac with preferreditemsize set to -1
Recent Applications stack on 27″ iMac with preferreditemsize set to -1



To have full control of how your recents or favorites stacks are created from the command line, copy the code below then substitute the values for the variables LISTTYPE, PREFERREDITEMSIZE and VIEWAS as appropriate:

defaults write persistent-others -array-add "<dict><key>tile-data</key><dict><key>list-type</key><integer>$LISTTYPE</integer><key>preferreditemsize</key><integer>$PREFERREDITEMSIZE</integer><key>viewas</key><integer>$VIEWAS</integer></dict><key>tile-type</key><string>recents-tile</string></dict>"; killall Dock



Recent Applications stack on 27
Recent Applications stack on 27″ iMac with preferreditemsize set to 20



About the author

A native Brit exiled in Japan, Steve spends too much of his time struggling with the Japanese language, dreaming of fish & chips and writing the occasional blog post he hopes others will find helpful.

Add comment


Recent Comments

Recent Posts