Re: Delete
Re: Delete
- Subject: Re: Delete
- From: Axel Luttgens <email@hidden>
- Date: Thu, 19 Aug 2010 17:41:42 +0200
Le 19 août 2010 à 02:39:09, André Renault a écrit :
> System Events does not accept alias. Suffix "as string", like this:
> tell app "System Events" to delete (alias "A:K:A:" as string)
Hello André,
If you allow, I would be tempted to say that there's too much contained in too few words. ;-)
System Events in fact understands AppleScript aliases.
For example, assuming there's a file "testfile" on the Desktop, following snippet
set ASAlias to alias ((path to desktop folder as text) & "testfile")
tell application "System Events"
properties of ASAlias
end tell
clearly shows the fact.
Now, it appears that System Events has a class "alias" in its dictionary as well.
So, let's ask System Events to build an alias of its own:
tell application "System Events"
set SEAlias to alias "testfile" of desktop folder
properties of SEAlias
end tell
Looking at the events log, both ASAlias and SEAlias look very similar:
alias "HD:Users:luttgens:Desktop:testfile"
and clearly refer to the same file.
But they aren't identical, as shown by:
ASAlias is SEAlias
--> false
or by:
{ASAlias, SEAlias}
--> {alias "HD:Users:luttgens:Desktop:testfile", alias "HD:Users:luttgens:Desktop:testfile" of application "System Events"}
There is thus "alias" and "alias"...
So, back to Nelson's question:
set ASAlias to alias ((path to desktop folder as text) & "testfile")
tell application "System Events"
delete ASAlias
--> System Events got an error: can't make alias \"HD:Users:luttgens:Desktop:testfile\" into type reference.
end tell
Amusing.
When asked to get the properties of an AppleScript alias, System Events is able to coerce the alias into a System Events alias and return the corresponding set of properties.
When asked to delete the file referenced by an AppleScript alias, System Events forgets its knowledge about such aliases.
On the other hand, System Events is able to delete a disk item referenced by a System Events alias:
tell application "System Events"
set SEAlias to alias "testfile" of desktop folder
delete SEAlias
--> poof! no testfile any more...
end tell
Let's thus create another "testfile" on the Desktop, and see whether an AppleScript alias may be converted into some System Events object:
set ASAlias to alias ((path to desktop folder as text) & "testfile")
tell application "System Events"
ASAlias as alias
--> doesn't do anything: no event sent to System Events.
terminology conflict?
alias id (id of ASAlias)
--> alias "HD:Users:luttgens:Desktop:testfile" of application "System Events"
alias (ASAlias as text)
--> alias "HD:Users:luttgens:Desktop:testfile" of application "System Events"
alias (posix path of ASAlias)
--> alias "HD:Users:luttgens:Desktop:testfile" of application "System Events"
disk item id (id of ASAlias)
--> file "HD:Users:luttgens:Desktop:testfile" of application "System Events"
end tell
Beside the first one, all those objects are valid references for a delete operation; for example:
set ASAlias to alias ((path to desktop folder as text) & "testfile")
tell application "System Events"
delete alias id (id of ASAlias)
--> poof! (see above)
end tell
On the other hand, I can't manage to have System Events delete a disk item by using a raw text string:
set ASAlias to alias ((path to desktop folder as text) & "testfile")
tell application "System Events"
delete (ASAlias as text)
--> System Events got an error: can't make \"HD:Users:luttgens:Desktop:testfile\" into type reference.
end tell
It is true that some apps tend to implicitly coerce text strings into file references, even when such a behavior isn't officially documented.
But this doesn't seem to be the case with System Events here (tried on both 10.4.11 and 10.6.4). Am I missing something?
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
References: | |
| >Delete (From: "R. Nelson Byrne" <email@hidden>) |
| >Re: Delete (From: André Renault <email@hidden>) |