• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Automated Cleanup
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automated Cleanup


  • Subject: Re: Automated Cleanup
  • From: Michelle Steiner <email@hidden>
  • Date: Thu, 22 Mar 2001 09:26:03 -0800

On 3/22/01 8:54 AM, Christopher Jett <email@hidden> wrote:

>What I want to do is create an AppleScript that will go through the hardrive
>and delete each PDF that is over 1 year old. For instance, the AppleScript
>would be triggered on April 1st of this year and delete every PDF named
>04012000.pdf that is on the harddrive. I am a newbie to AppleScript, so how
>would I go about doing this?

Funny you should ask. I have a script that does exactly that.

set daysToKeep to 365
set longAgo to (current date) - daysToKeep * days
set counter to 0

try
thefilepath
on error
set the thefilepath to choose folder
end try
tell application "Finder" to set thefilelist to every item of ,
thefilepath whose modification date is less than longAgo

tell application "Finder" to move items of thefilelist to the trash

(*
The following lines report how many files have been moved to the trash,
and let you empty the trash if you want to do it right then.
*)

set counter to count thefilelist
set numOffiles to " files"
if counter is 1 then set numOffiles to " file"
set filesMoved to counter & numOffiles & " moved to trash."
tell application "Finder" to set TrashItems to count items of the trash
set EmptyQuestion to "Do you want to empty the trash now?"
set buttonList to {"Don't Empty", "Empty"}
if TrashItems = 1 then
set trashMsg to "There is only one item in the trash." & return &
EmptyQuestion
else if TrashItems > 1 then
set trashMsg to "There are a total of " & TrashItems & ,
" items in the trash." & return & EmptyQuestion
else
set trashMsg to "The trash is empty."
set buttonList to {"OK"}
end if

set dialogResponse to display dialog (filesMoved & return & trashMsg) as
string ,
buttons buttonList default button 1 with icon note giving up after 60
if button returned of dialogResponse is "empty" then
tell application "Finder" to empty the trash
end if

----------------------------------------------------------------------
| Michelle Steiner | We're not human beings having a spiritual |
| | experience. We're spiritual beings |
| email@hidden | having a human experience. |
----------------------------------------------------------------------


  • Prev by Date: Automated Cleanup
  • Next by Date: text file with resource fork
  • Previous by thread: Automated Cleanup
  • Next by thread: text file with resource fork
  • Index(es):
    • Date
    • Thread