使用applescript打开程序
第2部分问题: 我只是尝试从终端使用applescript运行程序,因此我尝试:使用applescript打开程序,applescript,Applescript,第2部分问题: 我只是尝试从终端使用applescript运行程序,因此我尝试: $ osascript tell application "iTunes" to activate 并获取错误: osascript: tell: No such file or directory 给出程序的完整路径也不起作用。我错过了什么?问题的第二部分是我最终想用applescript做什么。我想用它来打开我用py2app构建的应用程序。applescript可以打开任何mac应用程序,或者只打开某些已经
$ osascript tell application "iTunes" to activate
并获取错误:
osascript: tell: No such file or directory
给出程序的完整路径也不起作用。我错过了什么?问题的第二部分是我最终想用applescript做什么。我想用它来打开我用py2app构建的应用程序。applescript可以打开任何mac应用程序,或者只打开某些已经兼容的应用程序
谢谢,试试这个。请注意,在编写命令时使用“-e”。如果没有“-e”,您将给出要运行的applescript的路径。还要注意,string命令必须用引号括起来
osascript -e "tell application \"iTunes\" to activate"
如果你有一个多行的applescript,你可以在每行前面使用“-e”,就像这样
osascript -e "tell application \"iTunes\"" -e "activate" -e "end tell"
如果要打开应用程序,只需使用unix“open”命令
open "/path/to/application"
如果您想使用applescript打开一个应用程序,但“activate”命令不起作用(但它几乎可以用于所有操作),请告诉查找程序打开它。请记住,applescript使用冒号分隔的路径
osascript -e "tell application \"Finder\" to open file \"path:to:application\""
尝试:
你需要用单引号括起来: osascript-e'告诉应用程序“iTunes”激活' 否则,当您在bashshell中运行-e时(如在终端中),您可以使用“here document”向osascript发送多行代码 变成
osascript <<EOF
tell application "iTunes"
activate
end tell
EOF
osascript我对脚本也不熟悉
我很困惑,所以我浏览了一篇名为《AppleScript语言指南》的文章
当我浏览脚本命令项时,我了解到如果你想用applescript editor
在macos
中激活一个应用程序,你应该在编辑器中的代码下面键入,然后编译并运行它们!希望这个答案对您有所帮助,以下是代码:
// applescript editor code
----------
activate application "iTunes" line 1
----------
tell application "iTunes" to activate line 2
osascript的替代方案:
open -a Calendar
附近:
pkill Calendar
有没有可能知道在哪个工作区打开?我在这里学到的一个重要教训是单引号不起作用。你必须对-e参数使用双引号。你能指出一些说明这一点的文档吗?查看osascript的手册页,我没有看到提到这一点。
open -a Calendar
pkill Calendar