-- Coda Diff vs Server script, Copyright (c) 2009, Jeanffy -- All rights reserved. -- Permission is hereby granted to use, copy, modify, and distribute this -- source code, or portions hereof, for any purpose, without fee, subject -- to the following restrictions: -- -- 1. The origin of this source code must not be misrepresented. -- 2. Altered versions must be plainly marked as such and -- must not be misrepresented as being the original source. -- 3. This copyright notice may not be removed or altered from -- any source or altered source distribution. -- -- If you use this source code in a product, acknowledgment is not -- required but would be appreciated. -- -- THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -- THE PROJECT AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -- OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -- OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. on CodaScriptSettings() return {displayName:"Diff vs Server", inContextMenu:"yes"} end CodaScriptSettings tell application "Coda" try set allWindows to windows set theWindow to the first item of allWindows set windowName to name of theWindow -- get the site name, using the window name set cmd to "echo " & windowName & " | cut -d - -f2 | sed -e 's/^ *//' -e 's/ *$//'" set siteName to do shell script cmd set docs to documents if (count of docs) is greater than 1 then display dialog "Too many documents" else -- get local path and remote path of the file, and the file name repeat with doc in docs set localPath to (file path of (current editor of doc)) set remotePath to (browser remote path of doc) end repeat set fileName to (do shell script "basename \"" & localPath & "\"") -- among all registered coda sites, find the good one -- and get the address, user name and password set allSites to sites repeat with theSite in allSites if (site name of theSite) = siteName then set siteAddress to address of theSite set siteUserName to user name of theSite set sitePassword to password of theSite end if end repeat -- download the file on server in the /tmp folder set cmd to "curl ftp://" & siteUserName & ":" & sitePassword & "@" & siteAddress & "/" & remotePath & "/" & fileName & " > /tmp/" & fileName log cmd do shell script cmd -- open filemerge to display differences between server file and local file set cmd to "opendiff /tmp/" & fileName & " \"" & localPath & "\"" log cmd do shell script cmd end if on error beep return end try end tell