2017-01-27 5 views
0

私はOS Xアプリケーションのwebcamからlaunchdを使って背景画像をキャプチャするために 'imagesnap'コマンドを使用しています。imagesnapコマンドによる画像キャプチャ

ファイル名: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 

そして、私のplist(test.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>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> 

のように見える私は、アプリケーションバンドルパスにスクリプトとplistファイルの両方を保ちました。

私のos xアプリケーションでは、ログインボタンをクリックすると、pl30を/Library/LaunchDaemons/にコピーしました。

スクリプトは起動しています(launchctl load path_to_plist_in_LaunchDaemon_folder)をオンにしています(出力ファイルにはフォルダの作成などのログが表示されます)。

しかし、 'imagesnap' のため、それは

imagesnap: command not found 

エラー

を投げている。しかし、私はそれが正常に動作している

chmod +x CaptureCameraPic 
./CaptureCameraPic 

のような端末上でこのスクリプトを実行しているとき。

助けが必要です。

+0

'imagesnap'コマンドとは何ですか?私はそれを聞いたことがない - どこから来たの? –

+0

@MarkSetchell:確認してください、私はimagesnap refで質問を更新しました。 URL(http://www.iharder.net/current/macosx/imagesnap/)。 –

+0

ターミナルで 'imagesnap'を試してみてください。パスが見つかったら見つかります。その後、あなたのスクリプトに完全なパスを入れてください。 – Roger

答えて

0

@Rogierが示唆しているように、あなたのスクリプトにはimagesnapへの完全なパスが必要です。

which imagesnap 

または

find /usr /opt -name imagesnap -type f -print 

次に、あなたがあなたのスクリプトに次のように使用します:あなたがしていることを見つけることができます

/path/to/imagesnap ... 

また、スクリプトでいじりがたくさんありますもっと簡単にこれを行うことができます:

#!/bin/bash 

# Set a variable just once so there is less maintenance 
photodir="$HOME/Documents/MyApp/Camera" 

# Make the directory if it doesn't exist, don't complain if it does 
mkdir -p "$photodir" 

cd "$photodir" 
if [ $? -ne 0 ]; then 
    echo "Failed to set working directory to $photodir" 
    exit 1 
fi 
... 
/path/to/imagesnap ... 

また、あなたのタイムスタンプはかなり恐ろしいです - 後でそれを解析する必要があると想像してください!それにはいくつかの区切り記号を入れてください。

date +"%Y-%m-%d_%H:%M:%S" 
2017-01-27_10:24:35 
関連する問題