Re: Deleting Files With System Events
Re: Deleting Files With System Events
- Subject: Re: Deleting Files With System Events
- From: Paul Berkowitz <email@hidden>
- Date: Sun, 12 Dec 2004 19:34:17 -0800
On 12/12/04 6:56 PM, "Tom McKenna" <email@hidden> wrote:
> A quick observation, followed by a couple of questions...
>
> If I use run this script, the files on on my desktop are deleted:
>
> tell application "Finder"
> delete every file of desktop folder
> end tell
>
> If you want, you can double-click on the trash and find them (and even
> take them out of the trash). In fact, if you are in the Finder and you
> can type command-z and the files reappear on your desktop.
>
> If you run this script, the files are also deleted:
>
> tell application "System Events"
> delete every file of (path to desktop)
> end tell
>
> However these files seem to have disappeared completely -- they're not
> even in the trash!
>
> OK, here are my questions:
>
> Is this behavior correct?
Seems so to me.
> If this is correct, why is it correct?
Scripting the Finder emulates the Finder in the UI. The Trash is an artifact
of the Finder. 'trash' is a property of the (Finder) application, and its
type is trash-object, a Finder special class. System Events doesn't know
anything about a trash folder, neither in the UI nor on AppleScript. Its
application class knows nothing about any trash property, it doesn't have a
trash-object class.
In the Finder, when you press cmd-delete the selected item(s) is/are moved
to the Trash - that's a special implementation that protects users from
hasty errors. So scripting the Finder does the same thing, but that's a
_really_ special implementation of the command 'delete' in the Standard
Suite. In almost every other app, 'delete' means 'delete'. And so it is in
System Events too - 'delete' means 'delete'. The deleted file isn't
anywhere - it's gone. That's the same using shell scripts - rm just deletes.
(And of course so does Empty Trash in the Finder.) No Trash halfway house.
It can be assumed that a scripter using System Events will not be making
inadvertent deletions needing protection from himself. Test first.
System Events is not another name for "Finder". It handles some of what the
Finder used to take care of - in those cases telling the Finder passes it on
on to SE. But it does other things the Finder never heard of, and yet other
thing - like delete - differently or more efficiently than the Finder does
on its own.
> Are the files really and truly gone forever?
Yes. Do a search in Find in the Finder - visible and invisible items - and
you'll see.
> If they aren't, where are they?
They're gone.
--
Paul Berkowitz
_______________________________________________
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