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

A

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 com.apple.dock 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.

UPDATE: The technique described below doesn’t work with macOS Catalina 10.15. The requisite code is still added to the com.apple.dock.plist file, but with Catalina the OS appears to ignore it.

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 com.apple.dock 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:

<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>

 

 

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/Value stack 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:

Key/Value Display
<key>viewas</key><integer>1</integer> Fan
<key>viewas</key><integer>2</integer> Grid
<key>viewas</key><integer>3</integer> List

 

 

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 com.apple.dock 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:

LISTTYPE=1; \
PREFERREDITEMSIZE=20; \
VIEWAS=2; \
defaults write com.apple.dock 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.

1 response

1 Comment

  • Good article man! As you mentioned this method won’t work on MacOS Catalina and higher.
    After spending a couple of hours trying to find a way for it I finally found a reliable solution how to make this work on MacOS Catalina 10.15 and higher (Big Sur). There’s an app called Casana that has this option built-in.

    This app doesn’t seem to be expensive compared to how many hours I’ve spent trying to make this work without any results… https://casana-app.com

Steve

Recent Comments

Recent Posts