2016-11-01 2 views
0

USB 장치가 연결될 때마다 bash 스크립트를 실행하는 실행 에이전트가 있습니다. 한 번만 실행하고 싶지만 장치를 연결하면 스크립트는 10 초마다 계속 실행됩니다.실행 에이전트가 10 초마다 스크립트를 실행합니다.

#!/bin/bash 
open -a "Spotify"; 
sleep 11; 

내가 스크립트가 launchd에 생각을 할 때까지 최소한 10 초 실행하는 데 필요한 것을 읽으면서 나는 잠 11 추가 : 여기

<?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>com.example.program</string> 
    <key>Program</key> 
    <string>/Users/Peter/Desktop/test1.sh</string> 
    <key>LaunchEvents</key> 
    <dict> 
     <key>com.apple.iokit.matching</key> 
     <dict> 
      <key>com.apple.device-attach</key> 
      <dict> 
       <key>idProduct</key> 
       <integer>1476</integer> 
       <key>idVendor</key> 
       <integer>1356</integer> 
       <key>IOProviderClass</key> 
       <string>IOUSBDevice</string> 
       <key>IOMatchLaunchStream</key> 
       <true/> 
      </dict> 
     </dict> 
    </dict> 
</dict> 
</plist> 

스크립트입니다 : 여기

는 PLIST입니다 그 일을 끝냈다. 그러나 이것은 도움이되지 않습니다. launchctl list com.example.program을 실행하는 단말기에서

을 제공합니다

기본적으로
"LimitLoadToSessionType" = "Aqua"; 
"Label" = "com.example.program"; 
"TimeOut" = 30; 
"OnDemand" = true; 
"LastExitStatus" = 0; 
"Program" = "/Users/Peter/Desktop/test1.sh"; 

답변

0

는 launchd에 자신의 시작 조건은, 을 충족 할 때 프로그램을 시작하고 그들이 종료하거나 충돌하는 경우를 다시 시작합니다. 스크립트를 다시 시작하지 않으려면 .plist에 <key>KeepAlive</key><false/>을 추가 한 다음 (언로드 한 후 다시로드하십시오). launchd가 "남은"Spotify 프로세스를 종료하지 못하도록하려면 을 추가해야 할 수도 있습니다 (이 기능이 없어도 작동한다고 생각하지만).

+0

불행히도 이러한 키를 추가해도 차이가 없습니다. 흥미로운 점은 launchctl list com.example.program을 터미널에서 실행할 때 새로운 키가 보이지 않는다는 것입니다. 그게 정상인가요? –

+0

@JohnSmith .plist를 다시로드해야하는 것 같습니다. 'launchctl unload/path/to/com.example.program.plist' 그리고'launchctl unload/path/to/com.example.program.plist'를 시도하십시오. (주의 : 이들과 함께'sudo'를 사용하지 * 마십시오. 에이전트가 아닌 데몬으로 취급 할 것입니다.) –

+0

내가 다시로드했습니다. 작동하지 않습니다. –

관련 문제