请考虑以下AppleScript:
on is_running(appName)
tell application "System Events" to (name of processes) contains appName
end is_running
set safRunning to is_running("Safari")
if safRunning then
tell application "Safari"
-- Stuff I only want executed if Safari is running goes here.
end tell
return "Running"
else
return "Not running"
end if
Run Code Online (Sandbox Code Playgroud)
问题:当我通过osascript命令行实用程序运行时,如果Safari未运行,它将启动并且脚本报告"正在运行".这不是我想要或期望的行为.请注意,在AppleScript编辑器中运行时,它可以按预期/预期工作.
这是一个osascript错误/已知问题吗?或者是因为我失踪的原因而在某种程度上是预期的行为?任何人都可以按需要让它工作吗?(顺便说一下,我正在运行OSX 10.7.5;我看不到如何osascript报告版本号).
如果你注释掉tell/ end telllines,它的行为就像我期望的那样:如果Safari没有运行,它就不会启动它,并打印"Not running".所以在我看来,tell是什么导致Safari被启动,但它不需要实际执行,只是出现在脚本中......?有一阵子,我想知道,如果这也许只是如何tell应该工作,但由于它并不像这样的AppleScript编辑工作,我想不是...
事实上,这是另一个具有类似行为的茜草版本:
on is_running(appName)
tell application "System Events" to (name …Run Code Online (Sandbox Code Playgroud) 我遇到了一个使用一小部分Applescript的shell脚本的问题.当我使用Applescript编辑器编译它时,它可以工作.它不在shell脚本中.
44:49:语法错误:预期行结束但找到命令名称.(-2741)23:28:语法错误:预期行结束但发现"之后".(-2741)
这是shell代码:
osascript -e 'tell application "System Events" -e 'activate'
osascript -e 'tell process "Application 10.5" -e 'set frontmost to true' -e 'end tell'
osascript -e 'delay 1' -e 'keystroke return' -e 'delay 1' -e 'keystroke return'
end tell
Run Code Online (Sandbox Code Playgroud)
Applescript(有效):
tell application "System Events"
activate
tell process "Application 10.5"
set frontmost to true
end tell
delay 1
keystroke return
delay 1
keystroke return
end tell
Run Code Online (Sandbox Code Playgroud)
[更新]/[已解决]
这解决了我试图修改applescript以在shell脚本中工作的任何问题:
## shell script code
echo "shell script code"
echo "shell script code" …Run Code Online (Sandbox Code Playgroud) 我osascript在Bash中使用通过Apple Script在通知中心(Mac OS X)中显示消息.我试图将文本变量从Bash传递给脚本.对于没有空格的变量,这可以正常工作,但不适用于带空格的变量:
定义
var1="Hello"
var2="Hello World"
Run Code Online (Sandbox Code Playgroud)
和使用
osascript -e 'display notification "'$var1'"'
Run Code Online (Sandbox Code Playgroud)
工作,但使用
osascript -e 'display notification "'$var2'"'
Run Code Online (Sandbox Code Playgroud)
产量
syntax error: Expected string but found end of script.
Run Code Online (Sandbox Code Playgroud)
我需要改变什么(我是新手)?谢谢!
我有一个我调用的shell脚本,osascript它osascript调用一个shell脚本并传入我在原始shell脚本中设置的变量.我不知道如何将该变量从applescript传递到shell脚本.
如何将变量从shell脚本传递到applescript到shell脚本......?
如果我没有意义,请告诉我.
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 …Run Code Online (Sandbox Code Playgroud) 以下工作在iTerm 2中打开两个选项卡.
我似乎无法弄清楚如何使用拆分窗格来改变它.
我试过应用我在几个论坛上看到的东西,但它永远不会奏效.有人能指出我正确的方向吗?
osascript <<-eof
tell application "iterm"
set myterm to (make new terminal)
tell myterm
launch session "Default session"
tell the last session
set name to "Server"
write text "cd $projectsFolder"
end tell
launch session "Default session"
tell the last session
set name to "Console"
write text "cd $projectsFolder"
end tell
end tell
end tell
eof
Run Code Online (Sandbox Code Playgroud) 我正在考虑写自己的小语言.
我找到了一些选择,但可以随意提出更多建议.
很多语言都在使用JVM,但除非你编写一个Java-ish语言,否则stdlib给你的所有功能都会让你感到难过; 它在动态的东西上也不是很好.
Parrot似乎是开发语言的好VM,但它有一点废弃/未完成/爱好项目的味道.
OSA是Applescript的推动力,而不是一个特别知名的虚拟机,但我使用的是Mac,它提供了良好的系统集成.
CLR + Mac似乎不是一个很好的组合......
我的语言将成为面向对象的功能并发数据流语言,具有强类型和Python和Lisp语法的混合.听起来不错,嗯?
[编辑]
我现在接受了Python,但我想更多地了解OSA和Parrot.
有谁知道如何使用applescript/osascript发送群组消息?我尝试过很多东西,但似乎没什么用.
我正在尝试使这个脚本工作.它是一个Bash脚本,用于获取一些变量,将它们放在一起并使用结果发送AppleScript命令.手动粘贴从to_osa后面的变量回显osascript -e到终端的字符串按我的意愿工作并期望它.但是当我尝试将命令osascript -e和字符串组合在一起时to_osa,它不起作用.我怎样才能做到这一点?
the_url="\"http://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash\""
the_script='tell application "Safari" to set the URL of the front document to '
delimiter="'"
to_osa=${delimiter}${the_script}${the_url}${delimiter}
echo ${to_osa}
osascript -e ${to_osa}
Run Code Online (Sandbox Code Playgroud)
除了手动工作之外,当我将所需命令写入脚本然后执行它时,脚本也可以工作:
echo "osascript -e" $to_osa > ~/Desktop/outputfile.sh
sh ~/Desktop/outputfile.sh
Run Code Online (Sandbox Code Playgroud) 我需要 AppleScript,当从命令行运行时,它会返回三件事:
例子:
我知道还有一些类似的问题。stackoverflow 上的答案在这里,但我无法将它们组合在一起以完成所有这些工作。非常感谢您的帮助。