Macro: “[ALL] Show Open Recent Files List”
This was requested in another thread:
Hey JM,
If I correctly understood the OP, she wanted a more generalized recent items list.
[Edit: macro redacted – I already posted it in the original thread.]
Trickster is a focused utility that watches file-open-events, stores them, and allows access to them via its UI.
We've tried to get the System's Recent Items via AppleScript, ASObjC and the shell – but Apple changed how they are stored – and as far as I know no one has figured out how to do it yet on post-10.9 (or so) systems.
Even if we manage to figure this out it won't allow for as much sophistication as Trickster.
Peter could probably create an event-tap to watch all file-open events, but creating a useful UI to manage them in Keyboard Maestro would be a pretty good chore.
-Chris
It’s possible to add a ‘secret’ icon to the Dock which does this. I believe you need something like Onyx to do it. I imagine that, once it’s working, there’s a way to access it via KM.
You are right that there is a way to get Recent Items in the dock.
Great snag, Jimmy. Thanks for sharing.
Yep, you're right. But looks like Jimmy has posted a solution for the Dock.
IAC, I still find my macro useful on a per app basis. For example, many times when I open Script Editor, it's to work on a recent script.
Agreed. I've been using similar macros for years. :smile:
-Chris
Indeed, thank you for sharing!
By any chance, have you been able to incorporate something along these lines into a keyboard maestro created window or palette, which can be called to show this in a window of choice from which to select?
I have not used this in a macro. I use Default Folder X for all recent files and folders.
Got it.
I think a combination of mdfind (spotlight command line interface) to find files modified in last 24 hours, and sort and limiting it to 10 or so files, and then transferring that information to applescript and have applescript show the dialog is perhaps one way to do it. But I am just not adept enough in these to be able to put it together.
I use launchbar for general navigation on the Mac. And being able to refer recently edited files (not necessarily for opening the files, could be for moving it to a different folder) through keyboard shortcuts is what I was trying to achieve.
Thanks again.
Hey @sims,
That’s not a bad idea. Here's a very quick and dirty proof-of-concept.
Remember to activate the macro after importing it.
Run it, and you'll get a pick-list that looks empty.
Type something like “.” to give it something to search for.
Then narrow down the search and pick 1 item, and hit <return>
to open that item in its default application.
This macro is unsophisticated and not well tested, but it should supply the building blocks for something better.
-Chris
Pick-List of Items Modified in the Last 24 Hours.kmmacros (6.8 KB)
Wow Chris! Thank you!
This is so cool. I have been wanting to do something like this ever since High Sierra was released. Because for some reason, the "Recents" in Finder, omits many files.
Towards improving the macro:
Thank you again!
Also, re regex, I tried these at regex101.com,
Sorry about the verbosity. Trying to understand and to explain my current understanding or lack of it.
I made some progress on mdfind.
mdfind -onlyin ~ '(kMDItemFSContentChangeDate > $time.now(-24h))' | grep -vwE "Library|Settings" | head
Linux commands are so powerful. Need to become better with them.
I don't think so. It should work as is out-of-the-box – remember though – you have to type a search string.
(By removing the prompt Title and not providing a search-string the prompt will show a list of less than 100 items. – I'll either change the first macro or upload a new one that incorporates this change.)
Something like this should do what you want:
mdfind -onlyin ~/Desktop -onlyin ~/Documents -onlyin ~/Downloads -onlyin ~/Dropbox 'kMDItemContentModificationDate >= "$time.now(-24h)"'
Invisible items with names prefixed with a dot should automatically be omitted by Spotlight.
Well, this action is a little quirky.
You can remove the title, and if the paragraphs in the search text are less than 100 they'll be shown automatically.
You can also give the acton an initial search string like “.” (dot). I don't particularly like this, because it's a purely literal search – and items without a dot in the name will be excluded.
Peter – Can the Prompt with List action be given a special variable to capture the last search? That would make it easy to bring it back where you last started which is often very useful.
@sims -- See the gear-menu in the Prompt with List action for the available options.
NOTE – If you install Dan Thomas' Spotlight Search Prompt macro, you have a great deal more control over the pop-up dialog than you do with KM's native Prompt with List action.
Yes – something of that sort could be coded into the macro.
If key down then
...
else
...
Peter – why does the Prompt with List action BALK when you hit ⌘Return – but is fine with ⌘ and any of ⇧, ⌃, ⌥.
Can this be changed? Or is there a good reason for the current behavior?
-Chris
Thank you again Chris.
I stumbled upon Dan Thomas's macro you have referred to. Looked great. But I will admit - I could not figure how I would put it to use :). I will look at it again to see how it can be leveraged here.
I am going to try the If key down then approach - but it sounds like you are suggesting that I try to use AppleScript. I will try to take a crack at it - I am certain I will bungle and not be able to solve it. Applescript appears to be such voodoo...
And, re the sorting of the mdfind output - I searched a good deal on the internet, and the best solution appears to be this Stackechange answer, but I am not sure how to incorporate it into the initial shell script command. I am going to try however.
No, you want PCRE – although it is not what Keyboard Maestro uses – it's acceptably close.
In the Keyboard Maestro Editor see:
Menu Bar > Help > ICU Regular Expression Reference
.
See this: Remove Parent Directory from a Path String
You don't know your way around RegEx or regex101 yet, so you're hitting some bumps.
Note that I've change the delimiter regex101 uses for the find-string from “/” to “%”, because my pattern itself contains a “/”. This saves me from having to escape it in the pattern and isn't relevant in a Keyboard Maestro search/replace action.
I've also made sure the global switch is ON, but the multi-line switch is OFF, because (?m)
turns multi-line ON in the pattern itself.
I've answered this in my previous post – let me know if I wasn't clear enough.
Nyet...
FInd:
([.?+()\{\}\[\]])
Replace
\$1
With this regular expression I'm escaping any RegEx special characters in the find-string that might cause problems when I go to find the full path from the file name returned from the Prompt with List action.
The outer parentheses are a capture. Capture 1 referred to as: $1
The inner brackets refer to a range of characters – in this case characters special to RegEx.
The replace pattern puts back any character in the range it finds with a prefixing backslash (an escape character).
The output of the Prompt with List action goes to a variable. I'm acting upon that variable.
Right – I’m converting back from file-name to file-path, so I can get to the actual item on-disk.
Questions are the forerunners of learning – don't apologize for asking.
I want people to spend at least a little time trying to answer their own questions before taking them public, but it's foolish to waste too much time and effort banging your head against the wall before asking for help.
I'll usually ask for help me'self if I'm still stumped after 30-60 minutes of research.
-Chris
No – I'm suggesting using a If Then Else action in Keyboard Maestro.
I was just using pseudocode to indicate the action.
That sort (pun intended) of thing gets tricky.
mdfind -onlyin ~/Desktop -onlyin ~/Documents -onlyin ~/Downloads -onlyin ~/Dropbox 'kMDItemContentModificationDate >= "$time.now(-24h)"' \
| awk -F'/' '{ print $NF"{ˆ}"$0 }' \
| sort --ignore-case \
| awk -F'{ˆ}' '{ print $NF }' \
| head -n 10
I cobbled together something along these lines by scraping using Google and some manual lookups. However, this expression of mine does not work because I think after the last line xargs is still evaluating...
mdfind -onlyin ~ '(kMDItemFSContentChangeDate > $time.now(-24h))' | grep -vwE "Library|Settings" | head -n 1 | xargs -0 stat -f '%m %N' | sort -n | cut -d ' ' -f2
The expression that you provided may be tricky but works
Update: Is your expression sorting in the order where most recent is listed at the top? I will need to dig around the syntax, but I think it is not doing that...
I will try the if then. For now, I changed the last action to Reveal file rather than Open.
I cobbled together this shell command which seems to sort the recent files in the reverse order of any change to the file.
mdfind -onlyin ~ '(kMDItemFSContentChangeDate > $time.now(-2h))' \
| tr '\n' '\0' \
| xargs -0 -n1 stat -f '%m %N' \
| sort -rn \
| cut -d ' ' -f 2-
However, the "prompt with list" action does not retain the order of the files in the variable that is used to "prompt with list".
Any way, to address this issue and retain the order?
Update: After some playing with the "prompt with list" action, it appears that the action alphabetically sorts the list it displays. And there does not seem to be a way to disable the inbuilt prompt.
Thank you.