Jump to content

RecentlyAdded — List directory contents by added date


Recommended Posts

Posted

This workflow is officially deprecated in favour of Thumbnail Navigation

 

List the contents of directories, ordered by add or modified date. rda sorts from the most recently added and rdz does the reverse; rdn sorts from the most recently modified and rdo does the reverse.


8Iuncvw.png


The list is auto-refreshed, making for a good way to track changes.


To act on the selections, use the standard Alfred shortcuts. You can activate file actions, dive into directories, preview files, reveal in Finder, add to the file buffer…


By default the Workflow searches in ~/Desktop and ~/Downloads. Change the value in the directories Workflow Environment Variable to use different paths, separated by commas.

Posted (edited)

I find this to be a very useful workflow, thanks!

 

A minor issue for me is that after I run rdn or rdo some applications with names matching the command (e.g. "Remote Desktop Connection") show first in the list, above the files in the Downloads directory. Is this possible to fix?

Edited by cands
Posted

Yes, you can simply go to the workflow (via Alfred’s preferences), and change the keywords (you just have to double-click each Script Filter node and change the top line, to something that will not interfere with your other apps.

Posted

Thanks, using other keywords solved the problem (I realize that it may not be possible to only show the results output from the workflow after invoking the commands)!

  • 6 months later...
  • 5 months later...
Posted
2 hours ago, Jasondm007 said:

@vitor - I love this workflow! Thanks for sharing!!

 

Thank you. Glad you find it useful.

 

2 hours ago, Jasondm007 said:

Out of curiosity, is there any way to sort by the date added field?

 

There is, but I do not intend to add it to the Workflow. This Ask Different answer and this blog post should put you on the right track.

Posted

Thanks for the suggested materials concerning how I might implement having the workflow sort the download folder's contents by the date it was added.

 

After looking through everything, I'm afraid they're pretty far past my limited skillset. 

 

Thanks for your help though!!

Posted
4 hours ago, politicus said:

Is is possible to hide not completed Downloads from the search results?

 

Would have to look into it. But I’m not going to add it to the Workflow because seeing incomplete Downloads is useful (e.g. if you cancel a download and want to delete the incomplete file).

Posted
On 08/10/2017 at 1:57 AM, Jasondm007 said:

how I might implement having the workflow sort the download folder's contents by the date it was added.

 

The date added is stored in the Spotlight metadata, so you’d have to use something like mdls to retrieve it.

Posted
On 13/10/2017 at 6:36 PM, vitor said:

 

That explains why it's way slower than the other variants. How about turning on "Alfred filters results" for that one?

 

Also, I'm seeing the following error for all commands (although they all still seem to work):

Code 2: /bin/bash: -c: line 13: syntax error near unexpected token `fi'
/bin/bash: -c: line 13: `fi'

Posted (edited)
1 hour ago, deanishe said:

Also, I'm seeing the following error for all commands (although they all still seem to work):

 

Fixed that. Thank you.

 

1 hour ago, deanishe said:

That explains why it's way slower than the other variants. How about turning on "Alfred filters results" for that one?

 

The solution itself is pretty hacky. Wasn’t thinking of officially adding it to the Workflow. Conceptually, Downloads should be a directory where other apps put files and then we only take them out.

 

I also wouldn’t like the inconsistency: the current solution starts the search from anywhere on the string, including the middle of words. I find that somewhat important for downloaded stuff (where much/most of the time you don’t control the filename as it comes). Since that’s not something Alfred can currently do by itself, the two solutions would be inconsistent with each other.

 

This Workflow should be pretty safe to edit, though. It’s unlikely it’ll need further updates apart from the just released fix (it even still uses the XML Script Filter and is largely unchanged from its origins).

Edited by vitor
Posted
1 hour ago, vitor said:

Conceptually, Downloads should be a directory where other apps put files and then we only take them out.

 

I tend to leave quite a lot of stuff in ~/Downloads that doesn't have an obvious other place to be, so I always want most-recently added at the top, not most-recently accessed.

 

1 hour ago, vitor said:

the current solution starts the search from anywhere on the string, including the middle of words

 

Good point. That is preferable behaviour.

 

1 hour ago, vitor said:

This Workflow should be pretty safe to edit, though

 

Given the above, I think I'll whip up my own that caches the times. I'm not a fan of bash and/or perl.

  • 4 weeks later...
Posted

@vitor A few weeks ago, in this thread, you were nice enough to update this great workflow, adding the options to sort by the date added. More specifically, you added two options: one placing the newest item first, and another placing the oldest item first. To jog your memory I've added the script from the filter below (for the second option - file with the oldest date added is listed first).

IFS=$'\n'

files=$(mdls -name kMDItemFSName -name kMDItemDateAdded -raw "${HOME}/Downloads/"* | xargs -0 -I {} echo {} | sed 'N;s/\n/ /' | sort | cut -d ' ' -f 4- | grep --ignore-case ".*{query}.*" | perl -MHTML::Entities -CS -pe'$_ = encode_entities($_, q{&<>"'\''})')

echo "<?xml version='1.0'?><items>"
for file in ${files}; do
  echo "<item uuid='file' arg='${file}' type='file'>"
  echo "<title>$(basename ${file})</title>"
  echo "<subtitle>${file}</subtitle>"
  echo "<icon type='fileicon'>${file}</icon>"
  echo "</item>"
done
echo "</items>"
fi

 

While the query works great - as it pulls the items up in their proper order - unfortunately, they're not clickable. When I press return on the file that I'd like to open, the files never actually open. In addition, all of the icons/thumbnails in the query just look like white (see image below).

 

Any ideas for how I might amend your code above to operate like usual?

 

As always, thanks a ton for all of your help!

 

5a03e45829c3b_ScreenShot2017-11-08at9_05_07PM.jpg.94c407210fbf403c41525537d8a29987.jpg

 

 

 

 

Posted

Fixed.


For reference:

IFS=$'\n'

files=$(mdls -name kMDItemFSName -name kMDItemDateAdded -raw "${HOME}/Downloads/"* | xargs -0 -I {} echo {} | sed 'N;s/\n/ /' | sort | cut -d ' ' -f 4- | grep --ignore-case ".*{query}.*" | perl -MHTML::Entities -CS -pe'$_ = encode_entities($_, q{&<>"'\''})')

echo "<?xml version='1.0'?><items>"
for file in ${files}; do
  file="${HOME}/Downloads/${file}"
  echo "<item uuid='file' arg='${file}' type='file'>"
  echo "<title>$(basename ${file})</title>"
  echo "<subtitle>${file}</subtitle>"
  echo "<icon type='fileicon'>${file}</icon>"
  echo "</item>"
done
echo "</items>"
fi

 

Posted

Last question, @vitor , I promise!

 

For those of us without coding backgrounds, do you have any favorite resources that you'd recommend to others interested in tweaking the RecentDownloads workflow? More specifically, I'd like to learn how to use some of the other spotlight metadata to restrict the output further, but - as a newbie - I'm not exactly sure where to start with some of these things.

 

For example, if wanted to restrict the output to certain file types, it looks like using the kMDItemKind field might be a good way of doing that. However, I don't have enough understanding of how your script is using these elements to provide the output (i.e., and this is a "ME" problem and nothing with the script). I've tried adding these elements, but it's clearly not working ... and I don't know enough to efficiently problem shoot.

 

 In any event, I'd just like to learn how to some of these metadata elements without bothering you and other equally nice people in the Alfred community. Thanks for your help!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...