使用osascript GUI命令进行Bash问题

时间:2013-05-08 04:41:41

标签: macos bash applescript osascript

我正在尝试自动执行在OSX中启动应用程序并在安全代理程序提示符下键入管理员密码的过程。我希望避免使用AppleScript GUI脚本,但是管理员提示的根本原因是如此复杂和复杂,我不会去那里。

以下是OSX管理员在本地运行时完美运行的脚本。 IE浏览器。来自终端adminaccount# /usr/local/bin/ReasonScript.sh

#/bin/sh
sudo /usr/bin/osascript <<EOF
launch application "Reason"
    tell application "System Events"
        repeat until (exists window 1 of process "SecurityAgent")
            delay 0.5
        end repeat
        tell window 1 of process "SecurityAgent"
            tell scroll area 1 of group 1
                set value of text field 1 to "adminaccount"
                set value of text field 2 to "adminpassword"
            end tell
            click button "OK" of group 2
        end tell
    end tell
EOF

exit 0

问题

我需要以root用户身份执行此脚本(我不知道,但我们的部署软件是如何做到的)。所以我尝试root# /usr/local/bin/ReasonScript.sh,我得到以下错误

105:106: syntax error: Expected “,” but found “"”. (-2741)

我已经完成了脚本,但我不是AppleScript的专家,但我找不到这种语法错误。但同时我不希望这个工作,因为ROOT用户没有GUI访问,所以这可能是失败的一部分。

然后我尝试假设root的本地用户权限...即root# sudo -u adminaccount /usr/local/bin/ReasonScript.sh

不幸的是我得到以下

shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Permission denied

如果Stackoverflow不是这个问题的正确位置,那么有一千个应用程序。我很困惑,我不知道如何进一步解决这个问题。它是AppleScript,它是osascript,它是BASH还是OSX的管理结构。

我很感激能用这种泡菜获得的所有帮助。

1 个答案:

答案 0 :(得分:0)

从手册页:

osascript will look for the script in one of the following three places:

 1.   Specified line by line using -e switches on the command line.

 2.   Contained in the file specified by the first filename on the command
      line.  This file may be plain text or a compiled script.

 3.   Passed in using standard input.  This works only if there are no
      filename arguments; to pass arguments to a STDIN-read script, you
      must explicitly specify ``-'' for the script name.

如果您要使用heredoc,则必须使用第三个选项。否则,您可以拥有一个applescipt文件,也可以使用-e。

逐行运行
相关问题