The title pretty much says it all. This Applescript will use BBEdit’s (or TextWrangler’s) internal diff functionality to compare the last two bits of text that have been copied to the clipboard. Tested in 10.5, not 10.6 (because I have work to do while all of you beta test Snow Leopard for me)
tell application "BBEdit"
set text_1 to (the contents of current clipboard)
set clip_index to the index of current clipboard
set clip_index to clip_index - 1
if clip_index is 0 then
set clip_index to 1
end if
set text_2 to the contents of clipboard clip_index
do shell script "rm /tmp/bbclipdiff_1.txt;touch /tmp/bbclipdiff_1.txt"
do shell script "rm /tmp/bbclipdiff_2.txt;touch /tmp/bbclipdiff_2.txt"
set file_1 to POSIX file "/tmp/bbclipdiff_1.txt"
set file_2 to POSIX file "/tmp/bbclipdiff_2.txt"
write text_1 to file_1 as text
write text_2 to file_2 as text
set the_result to compare file_1 against file_2
if not the differences found of the_result then
display dialog "Last Two Clipboards are Identical"
end if
return the_result
end tell
What if I Wrangle?
If you’re using the cheap-as-free TextWrangler just change the first line to read
tell application "TextWrangler"
Identical Text from Outside BBEdit
This uses BBEdit’s clipboard history feature (Edit ->> Show Clipboard). Things should work seamlessly for text copied in BBEdit itself, but if you’re copying text from another application there’s one quirk you’ll want to watch out for.
When you copy text outside of BBEdit, BBEdit will usualy shift its history accordingly. I have noticed a few instances when you’re copying identical text where BBEdit won’t shift it’s history, meaning that instead of two identical items being in the history, the second item never gets added. Normally this isn’t a problem, but since the point of the script is, in part, to quickly determine if two bits of text are the same or not, you’ll want to be aware of this quirk.