Re: Folder action question
Re: Folder action question
- Subject: Re: Folder action question
- From: Axel Luttgens <email@hidden>
- Date: Tue, 27 Jan 2004 12:41:33 +0100
Mark Butler wrote:
So you got the same result just got there a different way.
Is folder actions recognizing this as a new file every time it renames
the old one?
Seems to be the case.
Renaming is removing
--------------------
Just attach this one on a folder:
on adding folder items to Fldr after receiving Itms
display dialog "Added item(s)!"
end
and change the name of an enclosed item.
So, each time your script renames an enclosed item, this would
re-trigger the "adding folder items" event...
Renaming is removing and adding
-------------------------------
Now, if renaming an item is assimilated to adding an item, ther must
also be some item that has been removed, no?
Would be logical, so I tried:
on adding folder items to Fldr after receiving Itms
display dialog "Added item(s)!"
end
on removing folder items from Fldr after losing Itms
display dialog "Removed item(s)!"
end removing folder items from
Changing an item's name indeed yields two consecutive dialogs
("Removed", followed by "Added").
No communication through properties
-----------------------------------
Your goal is to rename items that are added to a folder, buth otherwise
letting those items in place.
But then, because of those renamings, your script will trigger removing
and adding events, thus calling your "on adding folder" handler anew.
And so on...
It seems that upon each event reception, a new instance of the attached
script object gets invoked, as properties allways start with their
initial value (the one hard-coded in the script's text).
This is true for each event. So, in our case, "adding" is sent to one
instance, then "removing" is sent to another instance, etc.
One would thus need some kind of external persistent storage.
For example, through a file.
Quick and dirty...
------------------
The easiest way: create a subfolder and move every added items to that
subfolder before renaming them.
But this still leaves the question open, should you want your folder to
also do something upon item removing...
Otherwise, you could devise a specialized stay open applet that would
watch the folder in question; you won't benefit from the ease of use
from folder actions, but you would regain information persistency.
If so is this why a fixed value works because it renames it to the same
thing everytime.
No: with a fixed name, the second and subsequent attempts to rename fail
because the name is already used.
But the behavior of folder actions with regards to execution errors
could be somewhat documented.
More exactly, I didn't find some references on such matters... ;-)
Anyway, it's difficult to find out the right explanation of the the
observed behaviors (beside the fact that lots of errors seem to be
silently discarded...).
And it could perhaps be a good idea to implement a distinguished event,
with a corresponding "on renaming folder items...".
After all, with regards to folders, renaming an item is as basic as
opening, moving, closing, adding and removing.
I am sure there has to be something wrong with how I
am writing it. Wouldnt this be the most basic use for folder actions?
Well, it seems you just considered the case that shouldn't even have
been thought about ;-)
HTH,
Axel
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.