Re: Getting label from a record
Re: Getting label from a record
- Subject: Re: Getting label from a record
- From: Emmanuel <email@hidden>
- Date: Wed, 19 Nov 2003 23:07:37 +0100
At 10:56 AM +0100 17/11/03, EBI Aktivitet wrote:
>
I'm trying to get a list of all the labels in a record. That is, not their
>
values, but the actual label name.
>
>
I have a record of all the properties of a document, and want to extract the
>
(unknown) labels to a list. I've tried a number of syntaxes, but nothing
>
seems to work right...
I've seen you got several replies, however you may want to consider using Smile since it does include specific tools for that kind of thing - more generally, for manipulating scripts by script.
The script belows finds all labels that do not include a colon (a rather rare case, you would admit). To find also those that include a colon you need a few additional lines, that would not help understanding how the script works.
The strategy here is 1. making the record into text (Smile's 'display' command) - 2. finding the first label (here I just locate the first occurrence of ":") (Satimage osax' 'find text' command) - 3. suppressing the said label out of the record (Satimage osax' 'suppress item' command) - then iterate until record is empty.
---------------------------------------
on GetLabels(r)
set labs to {}
repeat
set n to count r
if n = 0 then return labs
set lab to find text "\\{(\\|?)([^:|]+)\\|?:" in (display r) using "\\2" with regexp and string result
set end of labs to lab
set r to suppress item lab from r
try
if n is (count r) then set r to do script "suppress item " & lab & " from " & (display r)
end try
end repeat
end GetLabels
---------------------------------------
Example:
---------------------------------------
set f to path name of me
set r to {|art deco|:"r1", |bart, simpson|:"r2", |carte blanche|:"r|3", name:"Harry", bill:{fred:"}", arthur:{bert:42}}}
set r to r & (info for f)
GetLabels(r)
-- {"name", "creation date", "modification date", "icon position", "visible", "size", "folder", "alias", "name extension", "extension hidden", "package folder", "file type", "file creator", "displayed name", "default application", "folder window", "art deco", "bart, simpson", "carte blanche", "bill"}
---------------------------------------
Emmanuel
_______________________________________________
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.