1

The Apple menu "Recent Items" entry is handy, but at times I would like to be able to access it via command line, e.g. to change to a directory I was just working in with a GUI app. Is there a way to get access to at least the last open file or folder from Desktop to terminal?

Failing that, is there a way to access a smart folder from the command line (for example, if I have one that consists of files modified in the past 2 days).

  • This isn’t an answer but cd - puts you back in the immediately previous directory. – JL Peyret Feb 12 at 20:06
1

You can read the recent items plist file.

    defaults read $HOME/Library/Preferences/com.apple.recentitems

There's a lot of "noise" in the output. You can filter the "noise" with grep and list the last entry with tail which should be the last file opened (but not always the case).

    defaults read $HOME/Library/Preferences/com.apple.recentitems | grep "Name" | tail -n 1
  • I think you need $HOME/Library/Preferences... Sure a lot of junk in there. – Neil Jul 7 '15 at 20:10
  • I tried this in El Capitan and it didn't work. – Elias Zamaria Nov 8 '16 at 21:38
  • this pref item has disappeared... :( – Neil Sep 13 '18 at 16:38

You must log in to answer this question.

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