i’ll post this and hope it explains what i’m after…
if Variable = {1, 2, 3, 4, 5} then
set NewVar to {"a", "b", "c", "d", "e"}
desired results would be if Variable = 4 then NewVar = “d” …etc
basically looking for the ‘proper’ way to script that or do i just have to do a long line of if/then/else (which is how i’m doing it now )
property indexList : {5, 10, 20, 50, 100}
property valueList : {"a", "b", "c", "d", "e"}
set NewVar to missing value
set variable to 20
repeat with i from 1 to count indexList
if variable is item i of indexList then
set NewVar to item i of valueList
exit repeat
end if
end repeat
if NewVar is missing value then
-- error handling if indexList does not contain variable
else
-- do something with newVar
end if
fwiw, i’m trying to display some fractions from decimal inches (fractions of an inch rounded to the nearest 16th)… there’s a decently neat way to do this in numbers.app but applescript is seemingly lacking in operators(?)
this is how i’m doing it now with the help of your tip but maybe there’s a better way?
set decInch to 0.63453
set sixteenths to round (16 * decInch)
if sixteenths mod 2 is not 0 then
set fraction to (sixteenths as text) & "/16"
else
set fraction to item sixteenths of {"", "â…›", "", "¼", "", "â…œ", "", "½", "", "â…", "", "¾", "", "â…ž"}
end if
the decInch varies and is being defined by some calculations earlier in the script… it’s generally a .00000 #…
i’m still not sure about the text substitutions using ¼ etc when applicable but falling back on the x/16 in other spots… but i imagine i’ll eventually make them all “1/16”, “1/8”, etc
anyway, if you know of any better ideas for handling this stuff, i’m all ears
thanks
jeff