简体   繁体   English

Mac OS X 10.10 Yosemite Bash脚本默认读取生成结果域/默认对不存在错误

[英]Mac OS X 10.10 Yosemite Bash script defaults read generates The domain/default pair of does not exist error

I am trying to check the default homepage in Safari on Mac OS X 10.10 Yosemite. 我正在尝试在Mac OS X 10.10 Yosemite上的Safari中检查默认主页。

On my vanilla system the homepage isn't actually set, so first I forcibly set the HomePage using command: 在我的香草系统上,实际上并未设置主页,因此首先我使用以下命令强行设置主页:

defaults write com.apple.Safari.plist HomePage www.google.co.uk

Now I can read the HomePage setting using this command: 现在,我可以使用以下命令读取“主页”设置:

defaults read com.apple.Safari.plist HomePage

www.google.co.uk www.google.co.uk

is the output. 是输出。

I need to do this for the console user using a Bash Script that is delivered and executed by Microsoft SCCM. 我需要使用Microsoft SCCM交付并执行的Bash脚本为控制台用户执行此操作。 The Microsoft SCCM Client runs under the machine's system account so running the defaults read command above does not report the logged-in user's setting. Microsoft SCCM客户端以计算机的系统帐户运行,因此运行上面的默认读取命令不会报告已登录用户的设置。 To work around this I am using commands that first determine the logged-in user's userID and then another to read the HomePage value using a full path to the logged-in user's (if applicable) instance of the Safari plist file. 要解决此问题,我正在使用以下命令,这些命令首先确定已登录用户的userID,然后再使用另一个命令来读取Safari plist文件的已登录用户(如果适用)实例的完整路径来读取HomePage值。

If I execute the top four lines manually, the expected homepage is stored in variable myuserhompage and is displayed as expected. 如果我手动执行前四行,则预期的主页将存储在变量myuserhompage中,并按预期显示。

myuser=$(stat -f%Su /dev/console)
myuserhompage="$(defaults read /users/$myuser/library/preferences/com.apple.Safari HomePage)"
if [[ ${myuserhompage} == "www.google.co.uk" ]] ;
then
  echo "homepage_set"
  exit 0
else
  echo "homepage_not_set"
  exit 1
fi

However when I run the same lines of code from within a Bash script, I see The domain/default pair of does not exist error. 但是,当我从Bash脚本中运行相同的代码行时,我看到域/默认对不存在错误。

By re-typing the text directly into the OS X VM instead of relying on copy/paste from a Windows host I now appear to get consistency between the terminal command line and scripted commands. 通过直接在OS X VM中重新键入文本,而不是依靠Windows主机上的复制/粘贴,我现在似乎获得了终端命令行和脚本命令之间的一致性。 This has resolved my issue. 这已经解决了我的问题。 It also highlighted an issue with the result evaluation which I have updated accordingly. 它还强调了我已经相应更新的结果评估问题。 Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM