Hello Gnarlodious,
Well, I wonder what is the problem with using simple loop?
Loop is the simplest and the cleanest way to do it.
--CODE 1
set t to "791
917
185"
set nn to {}
repeat with p in t's paragraphs
set end of nn to 0 + p
end repeat
return nn -- {791, 917, 185}
--END OF CODE 1
You can even define a Perl-like map() handler for processing list if it helps.
--CODE 2
set t to "791
917
185"
return map(asNumber, t's paragraphs) -- {791, 917, 185}
on map(func, aa)
script o
property xx : aa's contents
property yy : {}
property f : func
repeat with x in my xx
set end of my yy to my f(x's contents)
end repeat
return my yy's contents
end script
tell o to run
end map
on asNumber(t)
t as number
end asNumber
--END OF CODE 2
---
If you really want, 'run script' osax can do the conversion at once -
--CODE 3
set t to "791
917
185"
return run script ("{" & list2text(t's paragraphs, ", ") & "}") -- {791, 917, 185}
on list2text(aa, delim)
set astid to a reference to AppleScript's text item delimiters
set astid0 to astid's contents
try
set astid's contents to {delim}
set t to "" & aa
set astid's contents to astid0
on error errs number errn
set astid's contents to astid0
error errs number errn
end try
return t
end list2text
--END OF CODE 3
But it is not at all recommendable because -
a) it is much slower than loop methods; and
b) it has serious security hole and can be very dangerous (as shown in CODE 3a below)
--CODE 3a
set t to "791
917
display dialog "hello"
185"
return run script ("{" & list2text(t's paragraphs, ", ") & "}")
on list2text(aa, delim)
set astid to a reference to AppleScript's text item delimiters
set astid0 to astid's contents
try
set astid's contents to {delim}
set t to "" & aa
set astid's contents to astid0
on error errs number errn
set astid's contents to astid0
error errs number errn
end try
return t
end list2text
--END OF CODE 3a
Hope this may help,
H
Message was edited by: Hiroto