Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript to find dated file

I would like to have some sort of applescript or automator action to find finder items that have todays date in them (ideally only one file). The folder I would like to pull from is shown below. Any help would be appreciated.

OS X Yosemite (10.10.3)

Posted on Feb 10, 2016 8:29 AM

Reply
18 replies

Feb 10, 2016 11:45 AM in response to techteej

ok, a bit easier than I first thought (just needed to build an array of the Months to match your format).

I used Automator, If you need to use this in Applescript, just use: do shell script (edit: or use Pierre's Applescript below)


This searches the Desktop, so change the directory to the one you want to search.

Not sure how you want to report what was found, this creates a file on the Desktop, but you can change the second action to anything you want


User uploaded file


The Run Shell Script Action is:


MONTHS=(ZERO January February March April May June July August Septembet October November December)

ThisMonth=$(date "+%m")

ThisDay=$(date "+%d")

FileString="${MONTHS[$ThisMonth]} $ThisDay"

find $HOME/Desktop/ -iname *"$FileString"*

Feb 11, 2016 6:18 AM in response to techteej

Try running the following script from the Script Editor window:


set theSourceFolder to choose folder


set theDate to {month, day} of (current date)

set TID to AppleScript'stext item delimiters

set AppleScript'stext item delimiters to {space}

set theFileName to (theDate as text) & ".docx"

set AppleScript'stext item delimiters to TID


tell application "Finder"

(files of the entire contents of theSourceFolder whose name is theFileName) as alias list

end tell

Feb 10, 2016 12:30 PM in response to Tony T1

Edit: I didn't account for the leading zero.

easy fix, just need to add: -

Change:

ThisMonth=$(date "+%m")

ThisDay=$(date "+%d")

to

ThisMonth=$(date "+%-m")

ThisDay=$(date "+%-d")

so:


MONTHS=(ZERO January February March April May June July August Septembet October November December)

ThisMonth=$(date "+%-m")

ThisDay=$(date "+%-d")

FileString="${MONTHS[$ThisMonth]} $ThisDay"

find $HOME/Desktop/ -iname *"$FileString"* -exec open {} \;


[Note: The file will be opened with -exec]

Feb 11, 2016 2:06 AM in response to techteej

Hello


You might try something like the following.


Shell script e.g.:



#!/bin/bash # # for localised month name by %B # # export LC_ALL=fr_FR.UTF-8 # export LC_ALL=de_DE.UTF-8 # etc # DIR=~/Desktop find "$DIR" -type f -iname "$(date '+%B %d').*" -print




AppleScript e.g.:



set d to (choose folder)'s POSIX path do shell script "DIR=" & d's quoted form & "; find \"${DIR%/}\" -type f -iname \"$(date '+%B %d').*\" -print" set rr to result's paragraphs repeat with r in rr set r's contents to r as POSIX file as alias end repeat return rr




Regards,

H

Applescript to find dated file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.