tag:blogger.com,1999:blog-4136549864035170205.post-60236437840848169982007-06-25T16:25:00.000-07:002008-02-11T17:00:06.185-08:002008-02-11T17:00:06.185-08:00Automatically update to latest WebKit each night.<p>You like webkit. You want the latest WebKit installed fresh each night while you sleep. You've looked at NightShift and found that it lacked a certain simplicity. You came here.</p> <p>Ok. We need a script to do the dirty work. Bash is fine:</p> <p><pre><code> #!/bin/bash # coding: utf-8 # Update Webkit # Alex Ross function handle { echo "An error occured!" exit $? } trap handle ERR APPLICATIONS="/Applications" ORG='http://nightly.webkit.org' LOCAL_REVISION=`cat /Applications/WebKit.app/Contents/Resources/VERSION` LATEST_REVISION_PATH=`curl --silent $ORG | grep -o "/files/trunk/mac/WebKit-SVN-r[0-9]*.dmg" | head -n 1` LATEST_REVISION=`echo \"$ORG+$LATEST_REVISION_PATH\" | grep -E '[0-9]{4,}' -io` if [ $LOCAL_REVISION -eq $LATEST_REVISION ]; then echo "Local WebKit r$LOCAL_REVISION is latest build, exiting." > /dev/console exit else echo "Updating WebKit.app to r$LATEST_REVISION..." > /dev/console fi curl -sL $ORG$LATEST_REVISION_PATH > /tmp/latest-webkit-svn.dmg hdiutil attach /tmp/latest-webkit-svn.dmg -mountpoint /tmp/latest-webkit-svn -quiet osascript <<-APPLESCRIPT tell application "Finder" activate set answer to display dialog "Would you like to update WebKit now? Your open Webkit and Drosera windows will close. Updating automatically in 30 seconds…" with title "WebKit Updater" buttons {"No", "Yes"} default button {"Yes"} giving up after 30 if button returned of answer is "Yes" or button returned of answer is not "No" then tell application "System Events" if (name of processes) contains "WebKit" then quit application "WebKit" saving no if (name of processes) contains "DroseraLauncher" then quit application "Drosera" saving no end tell end if end tell delay 0.25 tell application "System Events" if (name of processes) does not contain "WebKit" and (name of processes) does not contain "DroseraLauncher" then return 1 else return 0 end if end tell APPLESCRIPT rm -rf $APPLICATIONS/Drosera.app $APPLICATIONS/WebKit.app cp -R /tmp/latest-webkit-svn/Drosera.app $APPLICATIONS/Drosera.app cp -R /tmp/latest-webkit-svn/WebKit.app $APPLICATIONS/WebKit.app hdiutil detach /tmp/latest-webkit-svn -quiet rm /tmp/latest-webkit-svn.dmg echo "Webkit is up-to-date." > /dev/console </code></pre></p> <p>Paste all this junk into a text file and save it to /Library/Scripts/update_webkit.sh.</p> <p>We create a launch agent to run this script each morning at 4am. Open a blank text file and paste in this xml:</p> <code><pre> &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;!DOCTYPE plist PUBLIC &quot;-//Apple Computer//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt; &lt;plist version=&quot;1.0&quot;&gt; &lt;dict&gt; &lt;key&gt;Label&lt;/key&gt; &lt;string&gt;UpdateWebKit&lt;/string&gt; &lt;key&gt;UserName&lt;/key&gt; &lt;string&gt;root&lt;/string&gt; &lt;key&gt;GroupName&lt;/key&gt; &lt;string&gt;wheel&lt;/string&gt; &lt;key&gt;ProgramArguments&lt;/key&gt; &lt;array&gt; &lt;string&gt;/bin/sh&lt;/string&gt; &lt;string&gt;/Library/Scripts/update_webkit.sh&lt;/string&gt; &lt;/array&gt; &lt;key&gt;StartCalendarInterval&lt;/key&gt; &lt;dict&gt; &lt;key&gt;Hour&lt;/key&gt; &lt;integer&gt;4&lt;/integer&gt; &lt;/dict&gt; &lt;/dict&gt; &lt;/plist&gt; </pre></code> <p>That's it! You're done. Mmmm. I love the smell of fresh nightlies in the morning.</p>Alexhttp://www.blogger.com/profile/08423296523921081149noreply@blogger.com2