【发布时间】:2021-10-06 17:42:50
【问题描述】:
#!/bin/sh
SharePath=$(dscl /Search -read /Users/$USER OriginalHomeDirectory | awk '{ print $2 }' | sed -e 's/<[^>]*>//g'| awk -F'/' '{ print substr($0, index($0, $4))}')
prefix='/Volumes/'
LocalMountPoint=$prefix$SharePath
ln -s $LocalMountPoint "/Users/$USER/Desktop/P Drive"
所以当我从 bash 运行时,我有这个脚本可以完美运行。将其设置为 LaunchAgent 时失败,因为它将“/Users/$USER/Desktop/P Drive”评估为“/Users//Desktop/P Drive”并说该文件不存在。任何帮助将不胜感激。
这是 LaunchAgent plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.user.loginscript2</string>
<key>ProgramArguments</key>
<string>/Library/pdrive.sh</string>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/com.user.loginscript2.err</string>
<key>StandardOutPath</key>
<string>/tmp/com.user.loginscript2.out</string>
</dict>
</plist>
【问题讨论】:
-
它很可能在第 3 行失败,因为它也在尝试评估 $USER,但日志没有显示该错误
标签: macos macos-big-sur launchd