Here, with a text file containing :
[format]14 9.5 22 22.3 6. 16 30 31 11 20 17 17.5 9 25 19 22 24 28.3 20.6 19.1 22 11 22 22[/format]
the script return:
{14, 22, 6, 16, 30, 31, 11, 20, 17, 9, 25, 19, 22, 24, 22, 11, 22, 22}
which is normal because here the word “9.5” can’t be coerced as number.
I edited the script as :
property SortedAlready : false
property Temp : missing value
property Finish : missing value
set deciSep to character 2 of (0.5 as text) # get the local decimal delimiter
set TargetFile to choose file of type "txt" with prompt "Select input file: " default location (path to documents folder)
set theText to read targetFile
if deciSep is not "." then set theText to my remplace(theText, ".", deciSep)
set my_Words to every word of theText
log my_Words
set numeric_List to {}
repeat with my_Word in my_Words
try
set my_Number to (my_Word as number)
set end of numeric_List to my_Number
end try
end repeat
numeric_List
(*
copy numeric_List to realWorkingDataSet
display dialog realWorkingDataSet
*)
#=====
(*
replaces every occurences of d1 by d2 in the text t
*)
on remplace(t, d1, d2)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d1}
set l to text items of t
set AppleScript's text item delimiters to d2
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end remplace
#=====
and now, the script return the complete list of numbers.
{14, 9.5, 22, 22.3, 6, 16, 30, 31, 11, 20, 17, 17.5, 9, 25, 19, 22, 24, 28.3, 20.6, 19.1, 22, 11, 22, 22}
With the code used by JRWoodward, there is no need to close something.
This command is required if we use open for access which is not the case here.
Yvan KOENIG (VALLAURIS, France) dimanche 7 avril 2019 12:26:24