将 Bash shell 变量传递到 AppleScript 文件中
Passing a Bash shell variable into AppleScript file
我目前正在学习如何使用 bash shell AppleScript 脚本。我有个问题。
问题是如何将 bash 变量传递给 osascript
例子如下:
read input
foo $input
foo(){
osascript path/to/script.scpt
}
我的问题是如何将输入转换为 script.scpt 可以接受的内容,因为 script.scpt 无法识别 $1。谢谢
实际上这应该有效,因为 bash 会自动将 </code> 的值设置为您传递给 <code>foo
的参数。所以在这种情况下,它将是您阅读的输入。
我稍微整理了一下你的bash脚本..
#!/bin/bash
foo(){
echo "Calling Apple script with argument "
osascript script.scpt ""
}
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.
我目前正在学习如何使用 bash shell AppleScript 脚本。我有个问题。 问题是如何将 bash 变量传递给 osascript 例子如下:
read input
foo $input
foo(){
osascript path/to/script.scpt
}
我的问题是如何将输入转换为 script.scpt 可以接受的内容,因为 script.scpt 无法识别 $1。谢谢
实际上这应该有效,因为 bash 会自动将 </code> 的值设置为您传递给 <code>foo
的参数。所以在这种情况下,它将是您阅读的输入。
我稍微整理了一下你的bash脚本..
#!/bin/bash
foo(){
echo "Calling Apple script with argument "
osascript script.scpt ""
}
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.