LaunchDaemon每10秒运行一次 - OSX

时间:2016-09-27 15:17:02

标签: macos shell launch-daemon

我想要做的是检测iphone何时连接到Macbook Air(10.11.6),以及何时需要检索设备的UDID。为此,我创建了一个守护进程,当插入新的USB时触发脚本:

<?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>local.job</string>
        <key>LaunchEvents</key>
        <dict>
                <key>com.apple.iokit.matching</key>
                <dict>
                        <key>com.apple.device-attach</key>
                        <dict>
                                <key>IOMatchLaunchStream</key>
                                <true/>
                                <key>IOProviderClass</key>
                                <string>IOUSBDevice</string>
                                <key>idProduct</key>
                                <string>*</string>
                                <key>idVendor</key>
                                <string>*</string>
                        </dict>
                </dict>
        </dict>
        <key>Program</key>
        <string>/Users/cswtillster/Library/Mine/test2.sh</string>
</dict>
</plist>

这会触发此脚本:

#!/bin/sh
now="$(date)"
echo  "Current date and time %s\n" "$now" >> /Users/cswtillster/Library/Mine/usb_apple.txt

i=0
 for line in $(system_profiler SPUSBDataType | sed -n -e '/iPad/,/Serial/p' -e '/iPhone/,/Serial/p' | grep "Serial Number:" | awk -F ": " '{print $2}'); do
    UDID=${line}
    echo "$UDID" "%s\n" >> /Users/cswtillster/Library/Mine/usb_apple.txt
    udid_array[i]=${line}
    i=$(($i+1))
 done

 cnt=${#udid_array[@]}
 for ((i=0;i<cnt;i++)); do
    echo ${udid_array[i]}
 done

脚本检索de UDID但我的问题是它永远不会停止,它每隔约10秒运行一次:

Current date and time %s
 Tue Sep 27 16:06:39 WEST 2016
ffe6abf455a1ca722cbe1e2d970730411d0dc3fe %s

Current date and time %s
 Tue Sep 27 16:06:49 WEST 2016
ffe6abf455a1ca722cbe1e2d970730411d0dc3fe %s

Current date and time %s
 Tue Sep 27 16:06:59 WEST 2016
ffe6abf455a1ca722cbe1e2d970730411d0dc3fe %s

任何人都可以帮我解决这个问题吗?我需要的是脚本只为每个连接到usb端口运行一次。

0 个答案:

没有答案