• 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
Folder action to rename files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Folder action to rename files


  • Subject: Folder action to rename files
  • From: pete boardman <email@hidden>
  • Date: Wed, 24 Aug 2005 13:20:23 +0100

I'm having trouble with this folder action, which is supposed to add a date stamp to a file's name when added to a folder. It seems to repeat the renaming action on the same file each time when I add a bunch of files. Can anyone point out my error?

--
on adding folder items to this_folder after receiving these_items
try
set isoD to datestr(current date)
repeat with i in these_items -- a list of files?
set fn to name of (info for i)
set fne to name extension of (info for i)
set fneoffset to name extension of (info for i)
-- get name without extension...
set fname1 to (characters 1 thru ((offset of fneoffset in fn) - 2) of fn) as text
set newName to fname1 & "-" & isoD & "." & fne
tell application "Finder"
set name of i to newName
end tell
end repeat
on error e
tell application "Finder" to display dialog e as text
end try
end adding folder items to


on datestr(theDate)
-- returns eg 2004-11-28
set m to month of theDate as integer
set theShortDate to (theDate's year as text) & "-" & text -2 thru -1 of ("0" & m) & "-" & text -2 thru -1 of ("0" & theDate's day)
return theShortDate
end datestr


--

Thanks for any pointers!

Pete
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Folder action to rename files
      • From: Yvan KOENIG <email@hidden>
  • Prev by Date: Fwd: Mail and Attachments
  • Next by Date: lauch script via keyboard shortcut
  • Previous by thread: Re: [newby] Detect if a script was started from the command line
  • Next by thread: Re: Folder action to rename files
  • Index(es):
    • Date
    • Thread