在另一个脚本文件中获取变量

时间:2018-10-30 05:34:33

标签: applescript

我使用“运行脚本”命令为另一个文件运行程序。但是它没有显示结果。结果是一个变量,如何获得该变量?

代码1:

set xxx to {"ni", "bu", "en"}
set xxx2 to {"hao", "bu", "ni", "bu", "hao"}

repeat with item_number in xxx2
set booleanlist to {}
repeat with item_number_2 in xxx

    if contents of item_number_2 is not contents of item_number then
        set end of booleanlist to true
    end if

    if contents of item_number_2 is contents of item_number then
        set end of booleanlist to false
    end if

end repeat
set booleanlist_number to 0
repeat with booleanlist_number_2 in booleanlist
    if contents of booleanlist_number_2 is true then
        set booleanlist_number to booleanlist_number + 1
    end if
    if contents of booleanlist_number_2 is false then
        exit repeat
    end if
end repeat

if booleanlist_number = (count item of xxx) then
    set end of xxx to contents of item_number
end if

end repeat

代码2:

set xx to run script file "Macintosh HD:Users:mingxianzhao:Library:Mobile Documents:com~apple~ScriptEditor2:Documents:示例:run script and on run:Untitled.scpt" with parameters Character_used_for_the_query
choose from list xx

2 个答案:

答案 0 :(得分:1)

在代码1脚本的末尾添加function tr_get_ticker($post_ID) { $ticker = get_post_meta($post_ID, 'ticker', TRUE); if (empty($ticker)) { $tags = wp_get_post_tags($post_ID); foreach ($tags as $tag) { $term = $tag->name; $isTicker = strlen($term) <= 5 && ctype_upper($term); $isTickerWeak = strlen($term) <= 5; if ($isTickerWeak) { $ticker = $term; } if ($isTicker) { $ticker = $term; break; } } } return strtoupper($ticker);

答案 1 :(得分:0)

正如@foo所述,您需要在脚本“代码1”的末尾添加行return xxx

看过“代码1”,似乎您正在尝试将列表xxxxxx2合并为一个列表,但合并后的列表仅包含一个 strong>每个项目的副本,即您想要一组唯一的项目。

与您当前的实现相比,这可以更高效,更干净地完成:

set xxx to {"ni", "bu", "en"}
set xxx2 to {"hao", "bu", "ni", "bu", "hao"}

set xxx to xxx & xxx2

return unique(xxx) --> {"ni", "bu", "en", "hao"}


on unique(L)
    local L

    script
        property array : L
        property list : {}
    end script

    tell the result
        repeat with x in its array
            if x is not in its list then set ¬
                end of its list to x's contents
        end repeat

        its list
    end tell
end unique