Re: Getting the labels of a record
Re: Getting the labels of a record
- Subject: Re: Getting the labels of a record
- From: Kai <email@hidden>
- Date: Tue, 15 Apr 2003 23:38:37 +0100
on Tue, 15 Apr 2003 00:41:28 +0100, John Delacour <email@hidden> wrote:
>
At 11:51 pm +0100 14/4/03, John Delacour wrote:
>
>
>I've not tested this with all sorts of things, but it ought to work
>
>pretty well in most cases and could be elaborated to work in all
>
>cases.
>
>
Here it is elaborated to deal with strings embedded in lists.
>
>
You can still fool it, but it's not working badly for 40 minutes' work.
>
>
>
>
set reco to {_KEY_1_:{"a", 3.87, name, ""}, _KEY_2_:2,
>
_KEY_3_:"hello", _KEY_4_:{current date, 3 / 77}, _KEY_5_:{"oooo",
>
string}}
>
--
>
getkeys(reco)
>
-- => {"_key_1_", "_key_2_", "_key_3_", "_key_4_", "_key_5_"}
>
--
>
on getkeys(r)
>
set {fU, values_, listitems_, values_2} to {"/tmp/r", r as list, {}, {}}
>
repeat with v in values_
>
if class of v is list then
>
repeat with i in v
>
set i to contents of i
>
if class of i is string and i is not "" then
>
set end of listitems_ to i
>
end if
>
end repeat
>
end if
>
end repeat
>
repeat with i in values_ & listitems_
>
if class of i is string then
>
set end of values_2 to (contents of i)
>
end if
>
set end of values_2 to "t"
>
end repeat
>
set values_ to values_2 & "t"
>
set f to POSIX file fU
>
try
>
close access f
>
end try
>
open for access f with write permission
>
set eof f to 0
>
write r to f
>
close access f
>
set s to read f
>
set my text item delimiters to "TEXT"
>
set ls to text items 2 through -1 of s
>
set _keys_ to {}
>
repeat with i in ls
>
set s to "" & i
>
try
>
set c to ASCII number character 4 of s
>
set |key?| to text 5 through (4 + c) of s
>
if |key?| is not in values_ then set end of _keys_ to |key?|
>
end try
>
end repeat
>
set my text item delimiters to ""
>
_keys_
>
end getkeys
A very interesting approach, John!
I haven't tested the following variation exhaustively - but it seems to work
reasonably well here (with what I've thrown at it so far, at least)...
=================
to getStrings from l
set s to l's strings
repeat with i in l's lists
tell (getStrings from i) to if it is not {} then set s's end to it
end repeat
s
end getStrings
to getkeys from r
set {l, text item delimiters} to {getStrings from r, ASCII character 1}
set {k, n, l, s, text item delimiters} to [NoBreak]
{{}, 4, (l as string)'s text items, {r} as string, "TEXT"}
set {s, m, text item delimiters} to [NoBreak]
{s's text items 2 through -1, n + 1, {""}}
repeat with i in s
if (count i) is greater than n and "type" is not in i then [NoBreak]
tell i's text m through (n + (ASCII number i's character n)) to [NoBreak]
if it is not in l then set k's end to it
end repeat
k
end getkeys
tell application "Finder" to set r to {Key_1:{"a", 3.87, [NoBreak]
{Sub_Key_A:"A"}, name, ""}, Key_2:2, Key_3:"hello", [NoBreak]
Key_4:{current date, 3 / 77}, Key_5:{"oooo", {Sub_Key_B:"B"}, string, list}}
getkeys from r
--> {"key_1", "sub_key_a", "key_2", "key_3", "key_4", "key_5", "sub_key_b"}
=================
(You'll see that, since I couldn't get the script to run OMM with the
keyword 'name' present, I used a Finder tell block to assign the values to
the variable 'r'.)
--
Kai
_______________________________________________
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.