I’m writing a script to help me keep my desktop clean. I doubt I’m alone in having a problem with cluttered desktops. Anyway, I need to get the date modified of an item. If the item hasn’t been touched in four days the script will move it. Can anyone give my some code to get the days old of an item?
: I’m writing a script to help me keep my desktop clean. I
: doubt I’m alone in having a problem with cluttered
: desktops. Anyway, I need to get the date modified of
: an item. If the item hasn’t been touched in four days
: the script will move it. Can anyone give my some code
: to get the days old of an item?
below I have a short script which will let you choose a file and determine & display its age in days based on its modification date. You will need to have the OSAXEN “Date Calculations” installed in your scripting additions folder of your system folder. This is available in the scripting additions of bbs.macscripter.net
tell application “Finder”
set zero to 0
set myChoice to choose file “Select file whose age you want !”
set myName to name of myChoice
set information to info for myChoice
set modDate to modification date of result
set file_Date to date offset (modDate) by days -zero with day start, hour start and minute start
set Today to date offset (current date) by days -zero with day start, hour start and minute start
set file_Age to date interval starting file_Date ending Today
set file_Age to file_Age / (24 * 60 * 60) as integer
display dialog “The age of " & myName & " is " & file_Age & " Days”
end tell
"Can anyone give my some code to get the days old of an item? "
For a thorough set of exmaples on manipulating the date in Applescript, use the Applescript Guidebook section on dates. (Requires 8.6 or later).