這launchd的守護進程是系統守護進程(而不是用戶代理),並設計成從睡眠OSX:launchd的守護程序沒有運行我的腳本文件
運行喚醒時的腳本文件安裝代碼:
#!/bin/sh
#find current working directory. store as $curr. use to reference anything in $curr/mysecureview.
curr=$(pwd)
echo "+copy the plist to the system daemons directory."
cp $curr/sleepwatcher/config/sleepwatcher.system.plist /System/Library/LaunchDaemons/sleepwatcher.system.plist
echo "+create the /etc/mysecureview directory to contain all program files."
sudo mkdir /etc/mysecureview
echo "+copy the log file to contain the compiled set of log entries."
sudo cp $curr/log.txt /etc/mysecureview/log.txt
echo "+create the file to contain the individual set of pre-compiled log-entries."
sudo mkdir /etc/mysecureview/logs
echo "+copy the shell script to be used at bootup/wakeup"
sudo cp $curr/sleepwatcher/config/rc.wakeup /etc/mysecureview/rc.wakeup
echo "+move imagesnap"
sudo cp $curr/imagesnap-master/imagesnap /etc/mysecureview/imagesnap
#establishing root ownership of /etc/mysecureview/
#sudo chmod 700 /etc/mysecureview
#echo "+establishing root ownership of /etc/mysecureview/"
echo "========================"
echo "~Installation Succesful~"
echo "========================"
plist中:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>sleepwatcher.system</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/sbin/sleepwatcher</string>
<string>-V</string>
<string>-w /etc/mysecureview/rc.wakeup</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
腳本本身:
#!/bin/sh
sudo cd /etc/mysecureview/
sudo ./imagesnap
./imagesnap拍攝一張照片並將它放在同一個目錄中。該文件被命名爲「snapshot.jpg」。我搜索了整個mac,並沒有任何這個名字的.jpg。我認爲問題在於創建或安裝plist,但是在launchd上搜索OSX開發者頁面並不是很有幫助。
'sudo cd ...'改變目錄,然後立即退出改變目錄的shell。下一個'sudo'命令再次從默認/初始目錄開始。 –