在变量传递从shell脚本的AppleScript [英] Pass in variable from shell script to applescript
问题描述
我有一个shell脚本,我调用使用 osascript
,而 osascript
调用一个shell脚本并传递我在原来的shell脚本设置了一个变量。我不知道如何通过该变量从的AppleScript到shell脚本。
我怎样才能在变量传递从shell脚本的AppleScript到shell脚本...?
让我知道,如果我没有任何意义。
I = 0
在$(system_profiler SPUSBDataType线| sed的-n -e'/ iPad的/,/串口/ P'-e'/ iPhone /,/串口/ P'| grep的序列号| awk的-F:' {打印$ 2}');做
UDID = $ {}行
回声$ UDID
#I = $(($ I + 1))
睡眠1
osascript -e'告诉应用程序终端来激活'\\
-e'告诉应用程序系统事件告诉进程终端来击键T使用的命令下\\
-e'告诉应用程序终端做剧本CD$ current_dir'的前窗选定的选项卡'\\
-e'告诉应用程序终端做剧本./script.sh IP_ADDRESS'$ {#} UDID'和;在前面的窗口中选择选项卡 DONE
的Shell变量并不单引号内扩大。如果想shell变量传递给 osascript
你需要使用双,
报价。问题是,比你必须逃离osascript内需的双引号,如:
剧本
说你好用亚历克斯
您需要逃跑报价
文本=你好
osascript -e说\\$文字\\使用\\亚历克斯\\
这不是很可读,因此最好使用的是bash的定界符
功能,像
文字=世界,你好
osascript<< EOF
说$文字使用亚历克斯
EOF
,你可以写多行脚本中一个免费的,它比使用多个好得多 -e
ARGS ...
I've got a shell script that I call that uses osascript
, and that osascript
calls a shell script and passes in a variable that I've set in the original shell script. I don't know how to pass that variable in from the applescript to shell script.
How can I pass in a variable from shell script to applescript to shell script...?
Let me know if I don't make sense.
i=0
for line in $(system_profiler SPUSBDataType | sed -n -e '/iPad/,/Serial/p' -e '/iPhone/,/Serial/p' | grep "Serial Number:" | awk -F ": " '{print $2}'); do
UDID=${line}
echo $UDID
#i=$(($i+1))
sleep 1
osascript -e 'tell application "Terminal" to activate' \
-e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' \
-e 'tell application "Terminal" to do script "cd '$current_dir'" in selected tab of the front window' \
-e 'tell application "Terminal" to do script "./script.sh ip_address '${#UDID}' &" in selected tab of the front window'
done
Shell variables doesn't expanding inside single quotes. When want pass shell variable to osascript
you need to use double ""
quotes. The problem is, than you must escape double quotes needed inside the osascript, like:
the script
say "Hello" using "Alex"
you need escape quotes
text="Hello"
osascript -e "say \"$text\" using \"Alex\""
This not very readable, therefore it much better to use the bash's heredoc
feature, like
text="Hello world"
osascript <<EOF
say "$text" using "Alex"
EOF
And you can write multiline script inside for a free, it is much better than using multiple -e
args...
这篇关于在变量传递从shell脚本的AppleScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!