Hello.
I provide two versions of the same script here, one for ApplescriptEditor and the other for Script Debugger, so it should be fairly easy to adapt to other editors.
I use Filemerge for showing the differences, so you need either to install Developer tools, or rework it to work with for instance twdiff that comes with TextWrangler.
It is up to you to learn what you can do with FileMerge.
property scriptTitle : “ASEDiff”
tell application "AppleScript Editor"
if ((count its documents) < 1) then
tell me to display notification "You really need to have two documents open" subtitle my scriptTitle
error number -128
end if
set shortNm to name of its document 1
set text1 to quoted form of ("Active File" & linefeed & contents of its document 1)
set text2 to quoted form of ("Second File" & linefeed & contents of its document 2)
end tell
set theDir to do shell script "/usr/bin/mktemp -d -t " & quoted form of shortNm
set frontFile to "Active File"
set secondFile to "Second File"
set tempFn1 to quoted form of (theDir & "/" & frontFile)
set tempFn2 to quoted form of (theDir & "/" & secondFile)
do shell script "( cat <<<" & text1 & " >" & tempFn1 & "; cat <<<" & text2 & " >" & tempFn2 & "; /usr/bin/opendiff " & tempFn1 & " " & tempFn2 & " ) &> /dev/null &"
property scriptTitle : "ScriptDebuggerDiff"
tell application "Script Debugger 4.5"
if ((count its documents) < 1) then
tell me to display notification "You really need to have two documents open" subtitle my scriptTitle
error number -128
end if
set shortNm to name of its document 1
set text1 to quoted form of ("Active File" & linefeed & script source of its document 1)
set text2 to quoted form of ("Second File" & linefeed & script source of its document 2)
end tell
set theDir to do shell script "/usr/bin/mktemp -d -t " & quoted form of shortNm
set frontFile to "Active File"
set secondFile to "Second File"
set tempFn1 to quoted form of (theDir & "/" & frontFile)
set tempFn2 to quoted form of (theDir & "/" & secondFile)
do shell script "( cat <<<" & text1 & " >" & tempFn1 & "; cat <<<" & text2 & " >" & tempFn2 & "; /usr/bin/opendiff " & tempFn1 & " " & tempFn2 & " ) &> /dev/null &"
I threw this in as an afterthought, as it may be okay to have the same functionality in TextEdit as well!
property scriptTitle : "TextEditDiff"
tell application "TextEdit"
if ((count its documents) < 1) then
tell me to display notification "You really need to have two documents open" subtitle my scriptTitle
error number -128
end if
set shortNm to name of its document 1
set text1 to quoted form of ("Active File" & linefeed & text of its document 1)
set text2 to quoted form of ("Second File" & linefeed & text of its document 2)
end tell
set theDir to do shell script "/usr/bin/mktemp -d -t " & quoted form of shortNm
set frontFile to "Active File"
set secondFile to "Second File"
set tempFn1 to quoted form of (theDir & "/" & frontFile)
set tempFn2 to quoted form of (theDir & "/" & secondFile)
do shell script "( cat <<<" & text1 & " >" & tempFn1 & "; cat <<<" & text2 & " >" & tempFn2 & "; /usr/bin/opendiff " & tempFn1 & " " & tempFn2 & " ) &> /dev/null &"