RE: Unwinding the containment hierarchy of a reference
RE: Unwinding the containment hierarchy of a reference
- Subject: RE: Unwinding the containment hierarchy of a reference
- From: "Scott Babcock" <email@hidden>
- Date: Wed, 9 Feb 2005 14:05:26 -0800
- Thread-topic: Unwinding the containment hierarchy of a reference
Thanks for the help, has.
Regarding checking existence and creating filtered lists, here's an
example:
--------------------
on ToString(input)
local errmsg, revmsg, head, tail
try
{_:input} as text
on error errmsg
set revmsg to (reverse of (characters of errmsg))
set head to (offset of ":" in errmsg) + 1
set tail to -1 - (offset of "}" in revmsg)
return (get text head thru tail of errmsg)
end try
end ToString
tell application "TextEdit" to activate
tell application "System Events"
keystroke "," using command down
set windowRef to a reference to window "Preferences" of application
process "TextEdit"
set wantClass to "group"
set filterExp to "size is {340, 109}"
set wantObj to "button \"Revert to Default Settings\""
-- convert the window reference to text
set windowStr to my ToString(windowRef)
--> window "Preferences" of <<class pcap>> "TextEdit" of application
"System Events"
set existsStr to "exists " & wantObj & " of " & windowStr
set doesExist to run script existsStr
set filterStr to "get every " & wantClass & " of " & windowStr & "
whose " & filterExp
set filteredList to run script filterStr
end tell
--------------------
I could rewrite the existence check as a long series of 'if/then/else'
expressions, but I don't know of any other way that I could write the
filtered reference without creating a complicated expression parser that
essentially duplicates the one that already exists in AppleScript
itself.
The ToString() function presented here isn't a good general solution,
since it won't handle references with Unicode selectors in them.
It seems that an osax is the way to go, since it would be operating at a
very low level with respect to interpreting a request to process an
object specifier.
-----Original Message-----
Scott Babcock wrote:
>The goal is to add text so that I can run the revised code to check for
>the existence of named or indexed child elements or produce a filtered
>list of child references.
Not sure what you mean. Can you clarify/give examples?
>Is there a more graceful way to convert references to text?
Sure, though not in vanilla AppleScript. You'll need an osax or
scriptable application to do it from AppleScript, or use another
language like Python which, unlike AS, provides direct access to the
Apple Event Manager's functions and objects. I'm sure I've suggested
Python already: it's dead easy to do this kind of stuff there instead
of banging your head off a wall trying to do it in AppleScript. See
the aem/appscript project on my site and the Carbon.AE module in
MacPython - there's scads of material there you can use or
cannibalise to fit your needs.
>Can I send
>System Events object references to another application without System
>Events getting involved?
Yup. A reference is just a bunch of object specifiers chained
together. The recipient won't know it's a 'System Events' reference,
of course, since object specifiers don't hold that information
themselves. So if this application sends that reference back again
then AppleScript will assume that reference refers to it, not to
System Events. But if you're only sending it to be broken into text
then that's not an issue.
>I don't need to have the terminology resolved to friendly text; I
>actually prefer raw codes in this context.
Not hard. You just grab the topmost object specifier and recursively
extract its contents into a list. Easily doable in C, Python or Perl.
>Having the ability to process
>"foreign" object references will be useful for other tasks as well,
like
>getting a reference to an object's parent.
That's really something you should ask the target application to do
for you (assuming it provides that facility), since it's the only one
that truly understands what a givent reference actually means.
There's no guarantee that pulling the topmost object specifier off a
reference will yield a reference to the referenced objects' container
- that's not how it works.
HTH
has
--
http://freespace.virgin.net/hamish.sanderson/
------------------------------
Message: 16
Date: Wed, 9 Feb 2005 14:01:34 +0100
From: Bastiaan Boertien <email@hidden>
Subject: Re: HOWTO check if file is completly copied - OS9
To: Users AppleScript <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset="us-ascii"
I have scripts like yours and it works with the duplicate command
I just modified the script a little
Normally I mount the volume, then let the user choose witch file needs
to be modified from the server and then duplicate the file. After
duplicate is finished then modify the file
here's how I copy the file over the network.
set afpVolume to "networkdisk"
set afpServer to "server"
set afpUser to "user"
set afpPassword to "password"
set afpFile to afpVolume & ":folder:subfolder:name.txt" as string
set destinationFolder to (path to desktop folder)
mount volume afpVolume on server afpServer as user name afpUser with
password afpPassword
-- normally I let a user choose the file that needs to be copied from
the mounted volume
tell application "Finder"
set theName to name of file afpFile
with timeout of 900 seconds
duplicate file afpFile to destinationFolder with
replacing
end timeout
-- if you want to move,
-- duplicate te file and remove the file after duplicate
-- command after duplicate will not execute when duplicate is
finished
eject disk afpVolume --older versions of applescript is the
'eject'
command 'put away' like os9
end tell
try
set thefile to destinationFolder & theName as alias
on error
display dialog "duplication failed" buttons {"OK"} default
button "ok"
with icon stop -- with icon stop????? maybe a result in a error but not
sure
return
end try
--and the rest of the script
maybe this is where you looking for
greetings bastiaan
Op 9-feb-05 om 12:46 heeft Brendan Wilde het volgende geschreven:
>> I need to make a script for OS9, a file need to be modified.
>> The file is being copied over the network.
>> So before doing something with the file, I need to check is the file
>> is complete!
>> Anyone a trick to do this thing?
>
> I have a script that copies a file over a network then once it has
> finished copying it
> moves the original file...
>
> i did it by getting the size of original file
> then repeatedly getting the size of the new file
> until the size of new file is the same size as the size of the
> original file
>
> this is not really a good way to do it, it probably hogs memory
> but it works and i couldn't think of another way to do it...
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Applescript-users mailing list
(email@hidden)
> Help/Unsubscribe/Update your Subscription:
> email@hidden
>
> This email sent to email@hidden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 7041 bytes
Desc: not available
Url :
http://lists.apple.com/mailman/private/applescript-users/attachments/200
50209/777abfb3/attachment.bin
------------------------------
_______________________________________________
Applescript-users mailing list
email@hidden
http://lists.apple.com/mailman/listinfo/applescript-users
End of Applescript-users Digest, Vol 2, Issue 93
************************************************
_______________________________________________
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