• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting label from a record (part 2)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting label from a record (part 2)


  • Subject: Re: Getting label from a record (part 2)
  • From: Nigel Garvey <email@hidden>
  • Date: Tue, 18 Nov 2003 17:03:59 +0000

kai wrote on Tue, 18 Nov 2003 00:10:42 +0000:

> to getKeys from r with dupes
> tell r's class to if it is not record then error "Can't get keys from "
>& it & "."
> local dupes
> set r to {r} as string
[...]

>..which should handle something as perverse as this:
>
>set r to {subject:"Re: Getting label from a record", date:date "1/1", |time
>sent|:"14:36:25 pm", list:{list:{number:1576, string:string}},
>alias:{path:{name:{disk:{folder:{file:{item:false}}}}}}, file:"Macintosh
>HD:Desktop Folder:test", |initial values|:{list:{1, 2, 3, 4},
>|final\raverage|:10 / 4}}
>
>----------------------------
>
>getKeys from r with dupes
>
>--> {"date", "list", "list", "number", "string", "alias", "path", "name",
>"disk", "folder", "file", "item", "file", "subject", "time sent", "initial
>values", "list", "final
>average"}
>
>----------------------------
>
>getKeys from r without dupes
>
>--> {"date", "list", "number", "string", "alias", "path", "name", "disk",
>"folder", "file", "item", "subject", "time sent", "initial values", "final
>average"}

Nice one, Kai. :-) The old '{myRecord} as string' trick, huh?

Here's one that doesn't exploit bugs. It only handles labels from the top
level of a record, since anything else (in my view) counts as a "value" -
which is not what Adim originally wanted. (The labels of nested records
aren't much use anyway, out of context.) Bars are also preserved here in
label names.

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 (choose file))

try
r as real
on error msg
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "{"
set msg to msg's text from text item 2 to -1
(* set AppleScript's text item delimiters to "}"
set msg to msg's text 1 thru text item -2 *)
set AppleScript's text item delimiters to astid

set textValue to false
set barredLabel to false
set arrayValue to 0
set labelList to {}
set i to 1
considering case
repeat with j from 1 to count msg
set c to character j of msg
if textValue then
if c is "\"" and character (j - 1) of msg is not "\\" then set
textValue to false
else if barredLabel then
if c is "|" then set barredLabel to false
else if c is "{" then
set arrayValue to arrayValue + 1
else if c is "\"" then
set textValue to true
else if arrayValue > 0 then
if c is "}" then set arrayValue to arrayValue - 1
else if c is "|" then
set barredLabel to true
else if c is "," then
set i to j + 2
else if c is ":" then
set end of labelList to text i thru (j - 1) of msg
end if
end repeat
end considering

labelList
end try

--> {"|art deco|", "|bart, simpson|", "|carte blanche|", "name",
"bill", "creation date", "modification date", "icon position", "visible",
"size", "folder", "alias", "locked", "busy status", "file creator", "file
type", "short version", "long version", "default application"}

NG
_______________________________________________
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.

  • Prev by Date: Re: Scripting Fax Sending
  • Next by Date: delete files in nested folders
  • Previous by thread: Re: Scripting Fax Sending
  • Next by thread: Re: Getting label from a record (part 2)
  • Index(es):
    • Date
    • Thread