trigger folder with the oldest date as the folder´s name

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Hi,
I have several folders generated by other hazel rules.
The folders are named with dates that are a few days in the future.
For example:

2013-10-01
2013-10-02
2013-10-03

All the folders get filled with pdf-files all day long.
At 12.00 each day the folder with the oldest date as its folders name, here "2013-10-01" should be triggered.
But it is not sure that this folders creation or modification date is the least recent.
So that can´t be used to trigger the folder.
So it should be done with a rule like:
"read the folder´s names as dates or numbers an find the earliest or smallest"
or
"sort all the folders by name (ascending) and use the first"

Can this be done ?
Thanks for any help.

Graf Wetter
Graf_Wetter
 
Posts: 37
Joined: Thu Aug 25, 2011 7:18 am

I found this code to get the name of the correct folder
Code: Select all
tell application "Finder" to set theFolder to "/Users/xyz/Desktop/Neuer/Sammlung"
tell application "Finder" to set thefirstFolder to first item of (every paragraph of (do shell script "ls " & theFolder))

As I am very bad in scripting I don´t know how to use this in subsequent scripting.
For example in a renaming script to change the name of the so found folder to 2013-10-01_OK
Does anyone know how to do this ?

Thanks,
Graf Wetter
Graf_Wetter
 
Posts: 37
Joined: Thu Aug 25, 2011 7:18 am

finally got the problem solved.
this is my final code:
Code: Select all
tell application "Finder" to set theFolder to "/Path/to/Parent/Folder"
tell application "Finder" to set thefirstFolder to first item of (every paragraph of (do shell script "ls " & theFolder))

do shell script "mv " & theFolder & "/" & thefirstFolder & " " & theFolder & "/" & thefirstFolder & "_closed"

This renames the folder with the oldest date as its foldername from "2013-10-01" to "2013-10-01_closed"
and the subsequent hazel rule matches when it finds this "_closed" suffix

Thanks,
Graf Wetter
Graf_Wetter
 
Posts: 37
Joined: Thu Aug 25, 2011 7:18 am


Return to Support