Macos osascript GUI命令的Bash问题

Macos osascript GUI命令的Bash问题,macos,bash,applescript,osascript,Macos,Bash,Applescript,Osascript,我正在尝试在OSX中自动启动应用程序,并在安全代理提示下键入管理员密码。我希望避免使用AppleScript GUI脚本,但是管理提示的根本原因是如此复杂和复杂,我不想去那里 下面是由OSX管理员在本地运行的脚本。即从终端adminaccount\usr/local/bin/ReasonScript.sh #/bin/sh sudo /usr/bin/osascript <<EOF launch application "Reason" tell application "S

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

下面是由OSX管理员在本地运行的脚本。即从终端
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
我已经看过了脚本,但我不是AppleScript的专家,但我找不到这个语法错误。但同时,我不认为这会起作用,因为ROOT用户没有GUI可访问,所以这可能是失败的一部分

然后我尝试假设本地用户拥有root用户的权限。。。ie
root#sudo-u admincount/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
不幸的是,我得到了以下信息

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的管理结构

非常感谢您对我的帮助。

手册页:

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逐行运行它