2016-11-04 109 views
-2

所以我有了这个Run Shell Script (/bin/bash)(的Automator)在线Shell脚本执行

mkdir -p ~/Library/LaunchAgents 
curl -o ~/Library/LaunchAgents/com.zerowidth.launched.test.plist http://launched.zerowidth.com/plists/XXX-YYY-ZZZ.xml 
launchctl load -w ~/Library/LaunchAgents/com.zerowidth.launched.test.plist 

我想这项工作离线进行。因此,卷曲不会从互联网上获取http://launched.zerowidth.com/plists/XXX-YYY-ZZZ.xml,而是从离线下载,因为我已经下载了.xml文件并以某种方式将其导入Automator。

XXX,YYY-ZZZ.xml:

<?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.zerowidth.launched.test</string> 
    <key>ProgramArguments</key> 
    <array> 
     <string>sh</string> 
     <string>-c</string> 
     <string>echo test</string> 
    </array> 
    <key>RunAtLoad</key> 
    <true/> 
    <key>StartInterval</key> 
    <integer>20</integer> 
</dict> 
</plist> 
+1

什么是你的问题? –

+0

@ I0_ol我想离线执行bash脚本。这意味着我必须从我的电脑加载.xml文件。 –

回答

0

简单的ping可能会帮助确定,如果你上线

mkdir -p ~/Library/LaunchAgents 
if ping -c 1 launched.zerowidth.com > /dev/null ; then 
    curl -o ~/Library/LaunchAgents/com.zerowidth.launched.test.plist http://launched.zerowidth.com/plists/XXX-YYY-ZZZ.xml launchctl load -w ~/Library/LaunchAgents/com.zerowidth.launched.test.plist 
else 
    cp the_file_you_downloaded ~/Library/LaunchAgents/com.zerowidth.launched.test.plist 
fi 
+0

这不会帮助。我想要离线导入.xml文件(在我下载它之后)。我怎么做? –

+0

我没有看到你的问题与cp,但curl -o〜/ Library/LaunchAgents/com.zerowidth.launched.test.plist文件:// the_file_you_downloaded launchctl加载-w〜/ Library/LaunchAgents/com.zerowidth.launched .test.plist而不是cp可能会成为你的答案。 –