-- Paste link with text and tag -- © 2013 Augusto Campos - BR-Mac.org -- Copying and distribution of this file, with or without modification, -- are permitted in any medium without royalty provided the copyright -- notice and this notice are preserved. This file is offered as-is, -- without any warranty. set clip to (the clipboard as text) set JS to " function getlink() { var clip='" & clip & "'; var els=document.getElementsByTagName('a'); var i=els.length; while(i-->0) { if (els[i].href==clip) { // alert(els[i].innerHTML+' '+els[i].href); clip='' + els[i].innerHTML + ''; } } return(clip); } getlink(); " tell application "Safari" to set linktext to do JavaScript JS in front document tell application "BBEdit" tell window 1 set insertionP to get selection set text of insertionP to linktext end tell end tell