【Apple Script】Shell、Python に引数を渡して戻り値を取得する方法

Shell に引数を渡して戻り値を取得する

Apple Script のコード

    set arg1 to "123"
    set test2 to do shell script "
test1='0" & arg1 & "'
echo ${test1}
    "
    log test2

Apple Script の表示結果

(*0123*)

さらに、Shell 経由の Pythonコードから戻り値を取得する

以前やった、↓これを応用して、

Apple Script のコード

    set arg1 to "123"
    set test2 to do shell script "
test1=$(python /python/test.py " & arg1 & ")
echo $test1
    "
    log test2

Python の コード (test.py)

import sys

arg1 = ""
args = sys.argv
if len(args) > 1:
    arg1 = args[1]

if __name__ == '__main__':
    sys.stdout.write("test = " + arg1)

Apple Script の表示結果

(*test = 123*)