5

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

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

2 Answers 2

2

Consider something like this which is not exactly what you asked for but might be close.

mdfind 'kMDItemLastUsedDate >= $time.today()' | grep -vE '^.+Applications.+\.app'
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
3
  • I think you need $HOME/Library/Preferences... Sure a lot of junk in there.
    – Neil
    Commented Jul 7, 2015 at 20:10
  • I tried this in El Capitan and it didn't work. Commented Nov 8, 2016 at 21:38
  • 1
    this pref item has disappeared... :(
    – Neil
    Commented Sep 13, 2018 at 16:38

You must log in to answer this question.

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