I am using 'imagesnap' command (via shell script) for capturing image from webcam in my OS X application in background using launchd.
FileName: CaptureCameraPic
#!/bin/bash
timestamp=$(date +"%Y%m%d%H%M%S")
homeDirectory=$HOME/Documents
# Create Project Directory
if [ -d "$homeDirectory/MyApp" ]; then
echo "MyApp Directory exists"
cd $homeDirectory/MyApp
homeDirectory=$homeDirectory/MyApp
else
echo "MyApp Directory does not exists"
echo "Creating MyApp Directory"
cd $homeDirectory/
mkdir MyApp
echo "Created MyApp Directory successfully"
cd $homeDirectory/MyApp
homeDirectory=$homeDirectory/MyApp
fi
# Camera
if [ -d "$homeDirectory/Camera" ]; then
# Control will enter here if $DIRECTORY exists.
echo "Camera Directory exists"
cd $homeDirectory/Camera
camera_filename="IMG_${timestamp}.jpg"
echo "Take picture $camera_filename"
imagesnap "$camera_filename"
else
echo "Directory does not exists"
echo "Create directory"
cd $homeDirectory
mkdir Camera
cd $homeDirectory/Camera
camera_filename="IMG_${timestamp}.jpg"
echo "Take picture $camera_filename"
imagesnap "$camera_filename"
fi
And my plist (test.plist) looks like
<?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>GroupName</key>
<string>user</string>
<key>UserName</key>
<string>root</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>test</string>
<key>ProgramArguments</key>
<array>
<string>Path_to_ CaptureCameraPic </string>
</array>
<key>OnDemand</key>
<false/>
<key>Nice</key>
<integer>1</integer>
<key>StartInterval</key>
<integer>10</integer>
<key>StandardErrorPath</key>
<string>Path_to_Error_log.log</string>
<key>StandardOutPath</key>
<string>Path_to_Output_log.log</string>
</dict>
</plist>
I kept both the script and plist file in application bundle path.
In my os x application, on login button click, I copied the plist to /Library/LaunchDaemons/ .
The script starts running (using launchctl load path_to_plist_in_LaunchDaemon_folder) on (I can see logs print in output file, like folder creation, etc).
But for 'imagesnap', it is throwing error
imagesnap: command not found
But when I am running this script on terminal like
chmod +x CaptureCameraPic
./CaptureCameraPic
It is working fine.
Please need help.