KevinCork KevinCork - 1 month ago 6
AppleScript Question

AppleScript : create a list, then create a URL with items

I need to create a list of number
E.g of text value

55774455,114455777,11445544


And the result will be :

https://url.com/url/data=55774455%20OR%data=114455777%20OR%data=11445544


The challenge for me it the number of data is unknown but I guess I can count the list first with something like

set listSize to count of fatalist ##

I just can't think right now

Answer
on run argv
    set |list| to {55774455, 114455777, 11445544}

    set example1 to "https://example.com/data=" & my list2string("%20OR%20data=", |list|)

    repeat with |item| in |list|
        set |item|'s contents to "data=" & |item|
    end repeat
    set example2 to "https://example.com/" & my list2string("%20OR%20", |list|)

    {return, example1, linefeed, example1 = example2, return, example2}
end run

on list2string(delimiter, source) -- general utility
    try
        set {|applescript's text item delimiters|, AppleScript's text item delimiters} to {AppleScript's text item delimiters, delimiter}
        set |result| to source as string
        set AppleScript's text item delimiters to |applescript's text item delimiters|
    on error error_message number error_number from error_source partial result error_result to error_class
        set AppleScript's text item delimiters to |applescript's text item delimiters|
        error error_message number error_number from error_source partial result error_result to error_class
    end try
    |result|
end list2string

produces https://example.com/data=55774455%20OR%20data=114455777%20OR%20data=11445544