Converting enums to strings and v.v.
Converting enums to strings and v.v.
- Subject: Converting enums to strings and v.v.
- From: Steve Mills <email@hidden>
- Date: Tue, 23 Sep 2003 21:47:20 -0500
Recently I was writing a script that needed to present various enums to
the user as their English dialect strings, then convert the strings
back to enums. An example would be the color space property of a color
spec; 4-char code 'RGB ' should display as "RGB space", etc.
I tried the most simple thing I could think of, which was a coercion:
(color space of theColor) as string
-->"RGB space"
This worked! Later that day, it stopped working. The next day it didn't
work for a while, then suddenly it did. I asked the Script Debugger
list about it and Mark said that it should not work. But it did.
Anybody have any clues?
I worked around it by declaring companion lists:
property pRGBEnums : {RGB space, CMYK space}
property pRGBStrings : {"RGB space","CMYK space"}
Then wrote a function that takes an enum, an enum list, and a string
list:
on Enum2String(e, es, ss)
set num to number of items of es
repeat with i from 1 to num
if item i of es is e then
return item i of ss
end if
end repeat
end Enum2String
Plus the opposite (although that really wasn't necessary, except for
readability). This works as expected. I was wondering if I've
overlooked something that would make this easier and/or faster. There
are 13 pairs of lists and some have up to a couple dozen items.
Strangely, the terms true and false seem to be able to coerce to
strings all the time.
Steve Mills
Drummer, Mac geek
http://sjmills5.home.mchsi.com/
_______________________________________________
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.