Renaming file upon entering a folder

Hi,
I tried searching for the solution to my issue. But I’m running 10.2.8 (on THIS particular machine) & most of the mentions to what I would like to do referred to Folder Actions - which aren’t going to be an option for me due to my OS.

But basically I receive an e-mail once a day with an attached pdf. This file is always named the same thing. But what I would like to have happen is: as soon as the file is saved into it’s destination folder, I would like for it to be renamed with “XXX_” and the date. I’ve done some date formatting in the past. So that shouldn’t be an issue to append some date info to the file name.

But I’m stuck at the first part: the initial renaming upon the file entering the folder. Any suggestions/comments would be greatly appreciated. Thanks, Kevin

Sounds like a job for a stay-open application with an ‘on idle’ handler. They work like this:


on run
	-- do setup - this runs when the application is started to set things up.
	-- It is not necessary to have an 'on run' handler. The on idle
	-- handler runs right after this anyway. If you want this to
	-- run all the time after every login, list it your startup items.
	-- Quit it from it's dock icon.
end run

-- 'on idle' runs immediately following the 'run' handler if there is one, and
-- thereafter on the interval specified.
--  (An 'on run' handler is not required, so omit if there is no setup)
on idle
	-- In this section, you do your script operations every interval
	return xx -- do this every xx *seconds*.
end idle

on quit
	-- do stuff - assumes you want to clean things up or save
	-- preferences or variables before the program quits. This section
	-- runs only if the application is quit from the dock, or by any
	-- other means. It is not necessary to have one.
	
	-- if there is an on quit handler, then 'continue quit' must
	-- be the last statement or the script will not stop!
	-- The presence of an 'on quit' handler 'grabs' the
	-- system command to stop, so it will not complete the
	-- quit process until notified to do so. 'continue quit'
	-- does that.
	continue quit
end quit

Why not?

independent of the OS version, renaming a file in a folder with an attached folder action causes (normally) an infinite loop.
I would prefer a mail rule triggering an AppleScript, which does the rest :wink:

I guess I was thinking that folder actions were something new and only supported in 10.3 or 10.4. I’m assuming by your response that this is not necessarily the case? Thanks for the input, KB

I like this path too because it would not be constantly polling the machine. This seems like a more efficient way to do it.

That’s right. Folder actions are supported in 10.2 and date back to about OS 8.6 or so, but I don’t recall if they were immediately available in the earlier versions of OS X. But Stefan’s right about the renaming problem. His solution sounds the way to go.

Provided the OP uses Mail or Entourage. In Eudora I’d use a filter with its action set to “Move Attachments”. Obviously didn’t think of that approach, but fortunately StefanK did. :slight_smile:

With respect to the “infinite loop” problem in FAs, the drill is to move the file first and then change its name in the new place since you know everything you need to know about it.