Is it possible to use a Finder search to display all files created on a Monday, or on a Tuesday, etc.?
-
What a curious manner to slice the data files on a computer. I could see using AppleScript to generate smart searches to cover a small range of Mondays but since the day of the week is localized text and changes relative to the current system time zone (as opposed to what day it was when it was written to storage), it’s generated by SDK and not written directly to the metadata store for each file. You’ll probably need to write your own tool if you do intend to have 20 years of Mondays searchable…– bmike ♦Commented Jan 30 at 21:57
Add a comment
|
2 Answers
If you have Python 3 installed, this kind of thing may help:
Substitute a folder path with a string literal instead of
os.path.dirname(__file__)
- e.g.
'/'
. It will traverse the hierarchy of folders. Hasn't been tested for things like read rights - you may have some system folders it wouldn't let you traverse. - But try some place like Documents folder. It has to be an absolute path. So
'/Users/<profile>/Documents'
- e.g.
and a day of week eg
'SUN'
instead of'MON'
etc.
The script could be easily modified to add command line arguments (see sys.argv).
But it's enough to get you started.
__author__ = 'Jeremy Gordon Flowers'
from typing import List
def cls() -> None:
from os import system, name
clr = 'cls' if name == 'nt' else 'clear'
system(clr)
def get_files_for_dow(dir_path:str, dow:str) -> List[str]:
#https://docs.python.org/3/library/datetime.html#datetime.datetime.weekday
# 0 = MON, 6 = SUN
DOW = ['MON','TUE','WED','THU','FRI','SAT','SUN']
weekday = DOW.index(dow)
results = []
import os
import datetime
from pathlib import Path
for (dir_path, dir_names, file_names) in os.walk(dir_path):
for f in file_names:
fn = os.path.join(dir_path,f)
#https://docs.python.org/3/library/os.path.html#os.path.getctime
fd = os.path.getctime(fn)
d = datetime.datetime.fromtimestamp(fd)
if d.weekday() == weekday:
results.append(fn)
return results
def main() -> None:
cls()
import os
for f in get_files_for_dow(os.path.dirname(__file__), 'MON'):
print(f)
if __name__ == '__main__':
main()
-
Probably better to have the script call an
xattr
to dump a Monday tag on the file. Then spotlight can search for them (and they’ll pop up immediately in any running query or Smart Folder).– bmike ♦Commented Feb 25 at 23:02 -
@bmike AFAIK xttr doesn't allow date arithmetic to do days of the week. How is that any better than os.path.getctime? And isn't tagging a manual process?– JGFMKCommented Feb 26 at 0:11
-
I mean to write either kMDItemKeywords or finder comments to add Monday, Tuesday, Wednesday, etc… and have your script modify the metadata for each file it finds rather than spitting out a list of files. Your script is awesome, and it could enable spotlight to be super and maybe do an idempotent write of metadata in case OP sets it up on cron to keep the index relatively fresh at all times.– bmike ♦Commented Feb 26 at 0:14
-
@bmike Got you. You could use this to periodically assign the meta tags.– JGFMKCommented Feb 26 at 7:19
- Search something in Finder
- Click on the circle with three dots.
- In the drop-down menu that appears, select Show Search Criteria
- A bar will appear with three drop-down buttons.
- Click the first drop-down button and select Created Date.
- Click the second drop-down button and select exactly.
- Click the third drop-down button and select your desired date.
- Replace your "something" from Step 1 with what you actually want to search.
-
That works to search for a specific date, not for a named day of the week. Commented Jan 5, 2023 at 16:00
-
Yeah, I think that's as far as Finder allows you to go. You'll just have to click it multiple times. There's a plus sign to the right of the date, so you can click it and search multiple Mondays at a time. Commented Jan 5, 2023 at 16:00
-
Manually looking up the date for every Monday of every week for the past 20 years and plugging that in, one by one, to a Finder query. Uhhhh, no. Commented Jan 5, 2023 at 16:11
-
-
This answer doesn't give specific weekday. Furthermore it doesn't work for Monterey 12.7.3.. In a similar fashion, to this answer, it's best to enter a character such a in the magnifying/search option, then click +.. The you can select Created Date, Today etc from combo boxes. Then remove the a from the search.– JGFMKCommented Feb 25 at 20:24