Hier zwei Beispiele, was man so mit dem Änderungsdatum oder Erstellungsdatum von Dateien in Ordner so anstellen kann. Und der Auslöser…
–hubionmac.com 08.09.2010
–set a folder’s name to creation date of one of it’s items…
–date string format 2010-01-01
set thefolder to choose folder
tell application “Finder”
set thedates to (creation date of every item of thefolder)
set item_dates to {}
repeat with a in thedates
if my make_dateString(a) is not in item_dates then
set item_dates to item_dates & my make_dateString(a)
end if
end repeat
— wenn also dateien von mehr als einem Tag in dem ordner stecken…
if (count of item_dates) > 1 then
set item_dates to choose from list item_dates with prompt “Oje, welche Datum soll ich denn nur nehmen…”
end if
set current_foldername to name of thefolder
set string_to_add to text returned of (display dialog “Soll noch etwas an den Ordner-Namen angehängt werden?
\”” & item_dates & ” ” & current_foldername & “\”” default answer current_foldername)
set newfoldername to item_dates & ” ” & string_to_add as text
set comment of thefolder to “Alter Name: \”” & current_foldername & “\””
set name of thefolder to newfoldername
end tell
to make_dateString(thedate)
set themonth to characters -2 through -1 of (“0” & (month of thedate as integer) as text)
set theyear to year of thedate
set theday to characters -2 through -1 of (“0” & (day of thedate as integer) as text)
return theyear & “-” & themonth & “-” & theday as text
end make_dateString
— hubionmac.com 08.09.2010
–sets modification date of a folder to the latest modification date of its items
set thefolder to choose folder
tell application “Finder”
set thefiles to every item of thefolder
set thedates to (creation date of every item of thefolder)
set latest_date to modification date of item 1 of thefolder
repeat with i from 1 to (count of thefiles)
set current_item to item i of thefiles
if latest_date < (modification date of current_item) then
set latest_date to (modification date of (current_item as alias))
end if
end repeat
set modification date of thefolder to latest_date
end tell
–hubionmac.com >~2007 i think
–AppleScript Droplet to sort fieles into folders by creation date
on open these_items
set thelist to {make_dateString(current date, 1)} & {make_dateString(current date, 2)} & {make_dateString(current date, 3)} as list
choose from list thelist with prompt “Choose date format:”
if result as text = item 1 of thelist as text then
set theformat to 1
else if result as text = item 2 of thelist as text then
set theformat to 2
else if result as text = item 3 of thelist as text then
set theformat to 3
end if
repeat with this_item in these_items
tell application “Finder”
— set thedate to creation date of this_item
set thedate to modification date of this_item
set theLocation to quoted form of POSIX path of ((folder of this_item) as alias)
end tell
set foldername to make_dateString(thedate, theformat)
try
do shell script “cd ” & theLocation & “;mkdir ” & quoted form of foldername
end try
set the_item to quoted form of POSIX path of this_item
— 2008-05-26 -n Option add, so files are not overwritten
do shell script “cd ” & theLocation & “;mv -n ” & the_item & ” ./” & quoted form of foldername & “/”
end repeat
end open
on get_month_number(incomingDate)
— works with systems <OS X 10.4
copy incomingDate to b
set the month of b to January
set month_number to “0” & (1 + (incomingDate – b + 1314864) div 2629728) as text
return (characters -2 through -1 of month_number) as text
end get_month_number
on make_dateString(thedate, theformat)
if theformat = 1 then
set theday to characters -2 through -1 of ((“0” & day of thedate) as text) as text
set thestring to (year of thedate) & “-” & get_month_number(thedate) & “-” & theday
else if theformat = 2 then
set thestring to (year of thedate) & “-” & get_month_number(thedate)
else if theformat = 3 then
set thestring to (year of thedate)
end if
return thestring as text
end make_dateString