与osascript GUI命令的bash问题

问题描述:

我试图自动化在OSX中启动应用程序并在安全代理提示符处输入管理员密码的过程。我希望避免使用AppleScript GUI脚本,但是管理提示的根本原因太复杂了,我只是不会去那里。与osascript GUI命令的bash问题

以下是由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# /usr/local/bin/ReasonScript.sh,我得到以下错误

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

我已经通过脚本走了,但我不是AppleScript的专家,但我找不到这个语法错误。但同时我不希望这样做,因为ROOT用户没有可访问的GUI,所以也许这是失败的一部分。

然后我试着从根部承担本地用户权限...即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 

一千appologies如果#1是不是这个问题的正确的地方。我很困惑,我不知道如何解决这个问题。它是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. 

如果你打算使用一个定界符,你将不得不使用第三个选项。否则,您可以使用applescipt文件,也可以使用-e逐行运行它。