Applescripting multi strings into one

Trying to create a "master" string containing results from other strings. But sometimes the strings are undefined because they weren't selected as an option.

I tried else if... is not equal to... but that didn't work.

Im trying to avoid having to write out every possible combination. Heres the current script.

Answered by red_menace in 719137022

To make sure a string is defined, you can initially declare it as an empty string, then replace the value as needed. Also, instead of 10 different variables, just use a list - that is what they are for. Since the strings are in a fixed order, items in a list can be assigned according to the selections, then the list coerced to a string, which will add them all together (selected or not):

set stringsList to {"", "", "", "", "", "", "", "", "", ""} -- 10 items

set the choices to {"Music Sharing", "Remove Network Icons", "Dual - Galley & Active", "HD video", "Hide Menu", "Hide Reactions", "Remove All Overlays", "Dual - Galley x2", "Remove Names", "Other"}
set the response to (choose from list choices with prompt "Select Advanced Dial String Command(s).
Use Command (⌘) to select multiple." with multiple selections allowed and empty selection allowed)
if the response is not false then repeat with anItem in the response
   if contents of anItem is "Music Sharing" then set item 1 of stringsList to "306"
   if contents of anItem is "Remove Network Icons" then set item 2 of stringsList to "307"
   if contents of anItem is "Dual - Galley & Active" then set item 3 of stringsList to "308"
   if contents of anItem is "HD video" then set item 4 of stringsList to "309"
   if contents of anItem is "Hide Menu" then set item 5 of stringsList to "504"
   if contents of anItem is "Hide Reactions" then set item 6 of stringsList to "508"
   if contents of anItem is "Remove All Overlays" then set item 7 of stringsList to "606"
   if contents of anItem is "Dual - Galley x2" then set item 8 of stringsList to "608"
   if contents of anItem is "Remove Names" then set item 9 of stringsList to "102"
   if contents of anItem is "Other" then set item 10 of stringsList to text returned of (display dialog "Enter other advanced string command(s)" default answer "")
end repeat

return the stringsList as string
Accepted Answer

To make sure a string is defined, you can initially declare it as an empty string, then replace the value as needed. Also, instead of 10 different variables, just use a list - that is what they are for. Since the strings are in a fixed order, items in a list can be assigned according to the selections, then the list coerced to a string, which will add them all together (selected or not):

set stringsList to {"", "", "", "", "", "", "", "", "", ""} -- 10 items

set the choices to {"Music Sharing", "Remove Network Icons", "Dual - Galley & Active", "HD video", "Hide Menu", "Hide Reactions", "Remove All Overlays", "Dual - Galley x2", "Remove Names", "Other"}
set the response to (choose from list choices with prompt "Select Advanced Dial String Command(s).
Use Command (⌘) to select multiple." with multiple selections allowed and empty selection allowed)
if the response is not false then repeat with anItem in the response
   if contents of anItem is "Music Sharing" then set item 1 of stringsList to "306"
   if contents of anItem is "Remove Network Icons" then set item 2 of stringsList to "307"
   if contents of anItem is "Dual - Galley & Active" then set item 3 of stringsList to "308"
   if contents of anItem is "HD video" then set item 4 of stringsList to "309"
   if contents of anItem is "Hide Menu" then set item 5 of stringsList to "504"
   if contents of anItem is "Hide Reactions" then set item 6 of stringsList to "508"
   if contents of anItem is "Remove All Overlays" then set item 7 of stringsList to "606"
   if contents of anItem is "Dual - Galley x2" then set item 8 of stringsList to "608"
   if contents of anItem is "Remove Names" then set item 9 of stringsList to "102"
   if contents of anItem is "Other" then set item 10 of stringsList to text returned of (display dialog "Enter other advanced string command(s)" default answer "")
end repeat

return the stringsList as string

Fantastic! Thank you!

Applescripting multi strings into one
 
 
Q