0
我有一个启动代理,只要连接了USB设备就运行bash脚本。我希望它只运行一次,但是当我连接设备时,脚本每10秒继续运行一次。启动代理每10秒运行一次脚本
这里是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>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>
下面是脚本:
#!/bin/bash
open -a "Spotify";
sleep 11;
我加了睡眠11,因为我读了剧本需要运行至少10秒钟,让launchd的思考它完成了它的任务。然而,这并没有帮助。
在运行launchctl list com.example.program
终端给出:
"LimitLoadToSessionType" = "Aqua";
"Label" = "com.example.program";
"TimeOut" = 30;
"OnDemand" = true;
"LastExitStatus" = 0;
"Program" = "/Users/Peter/Desktop/test1.sh";
不幸的是,添加这些键并没有什么区别。有趣的是,当我在终端中运行launchctl list com.example.program时,我没有看到这些新键。这是正常的吗? –
@JohnSmith这听起来像你需要重新加载.plist。尝试'launchctl unload/path/to/com.example.program.plist',然后'launchctl unload/path/to/com.example.program.plist'。 (注意:*不要*使用'sudo';这会把它当作一个守护进程,而不是一个代理。) –
我重新加载它。它不起作用。 –