AppleScript:创建一个列表,然后创建一个包含项目的URL

时间:2016-10-11 12:09:07

标签: list applescript

我需要创建一个数字列表 例如文本值55774455,114455777,11445544

结果将是:

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

我面临的挑战是数据的数量未知,但我想我可以先用类似

的方式计算清单。

将listSize设置为fatalist ##

的计数

我现在无法思考

1 个答案:

答案 0 :(得分:1)

property base : "https://example.com/"

on run argv
    set input1 to "55774455,114455777,11445544"
    set input1 to my string2list(",", input1)

    set input2 to "55774455 114455777 11445544" -- if input format can change
    set input2 to input2's words

    set output1 to base & "data=" & my list2string("%20OR%20data=", input2)

    set input1_ to input1's items -- for test

    repeat with |item| in input1
        set |item|'s contents to "data=" & |item|
    end repeat
    set output2 to base & "" & my list2string("%20OR%20", input1)

    {¬
        return, input1_, ¬
        return, input1_ = input2, ¬
        return, input2, ¬
        return, output1, ¬
        return, output1 = output2, ¬
        return, output2}
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

on string2list(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's text items
        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 string2list

生成https://example.com/data=55774455%20OR%20data=114455777%20OR%20data=11445544(以不同的方式)。