2016-11-04 113 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可能會成爲你的答案。 –