I have 2 scripts and they both work individually, but when I try to merge them, it's not working.
Script 1:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set listOfItems to "Tiago
Paulo
Sergio
Tiago"
-- List of names
set nameList to paragraphs of listOfItems
-- Initialize an empty list to store formatted names
set formattedNames to {}
-- Iterate through each name and format it
repeat with aName in nameList
set end of formattedNames to "\"" & aName & "\""
end repeat
-- Combine the formatted names into a single string with commas between them
set AppleScript's text item delimiters to ","
set formattedText to formattedNames as string
set AppleScript's text item delimiters to ""
So I can see the output as
"Tiago","Paulo","Sergio","Tiago"
... and that's what I want.
Script 2
This was copied from MacScripter.
set formattedText to {"Tiago", "Paulo", "Pedro", "Tiago"}
removeDups(formattedText)
to removeDups(l)
script foo
property foo2 : l
property okAddresses : {}
end script
considering case
repeat with i from 1 to count (foo's foo2)
set formattedText to ((foo's foo2)'s item i)
if formattedText is in foo's okAddresses then
else
set end of foo's okAddresses to formattedText
end if
end repeat
end considering
foo's okAddresses
end removeDups
I can see in Script Debugger that the duplicated name is removed, as expected.
Now when I try to merge them by replacing the list of names in Script 2, by the variable formattedText
in Script 1, it doesn't work
Final, merged script
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set listOfItems to "Tiago
Paulo
Sergio
Sara"
-- List of names
set nameList to paragraphs of listOfItems
-- Initialize an empty list to store formatted names
set formattedNames to {}
-- Iterate through each name and format it
repeat with aName in nameList
set end of formattedNames to "\"" & aName & "\""
end repeat
-- Combine the formatted names into a single string with commas between them
set AppleScript's text item delimiters to ","
set formattedText to formattedNames as string
set AppleScript's text item delimiters to ""
removeDups(formattedText) --> {"a@a.e", "b@b.c", "d@a.h"}
to removeDups(l)
script foo
property foo2 : l
property okAddresses : {}
end script
considering case
repeat with i from 1 to count (foo's foo2)
set formattedText to ((foo's foo2)'s item i)
if formattedText is in foo's okAddresses then
else
set end of foo's okAddresses to formattedText
end if
end repeat
end considering
foo's okAddresses
end removeDups
@ComplexPoint - do you see anything weird here?