将Bash shell变量传递到AppleScript文件中



我目前正在学习如何将bash-shell脚本与AppleScript一起使用。我有个问题。问题是如何将bash变量传递到osascript中示例如下:

read input
foo $input
foo(){
osascript path/to/script.scpt $1
}

我的问题是如何将输入转换为script.scpt可以接受的东西,因为script.scpt无法识别$1。谢谢

实际上,这应该有效,因为bash会自动将$1的值设置为传递给foo的参数。因此,在这个场景中,它将是您读取的输入。

我把你的bash脚本清理了一下。。

#!/bin/bash
foo(){
echo "Calling Apple script with argument $1"
osascript script.scpt "$1"
}
read input
foo "$input"

有了这个AppleScript,

on run argv
return "hello, " & item 1 of argv & "."
end run

我得到这个输出。。

> ./test.sh
crazy world
Calling Apple script with argument world
hello, crazy world.

最新更新