function clipboard2hyperlink () {
if (!app.documents.length) {
return false;
}
var doc = app.activeDocument;
if (app.selection.length != 1 || !app.selection[0].hasOwnProperty('characters')) {
return false;
}
var text = app.selection[0].getElements()[0];
var shadow = doc.pages[0].textFrames.add(undefined, undefined, undefined, {geometricBounds: [0,0,1,1]});
shadow.parentStory.insertionPoints[0].select();
app.paste();
if ((/[\w]/).test(shadow.parentStory.contents.toString())) {
while (hiperlinkSources = text.findHyperlinks(), hiperlinkSources.length) {
hiperlinkSources[hiperlinkSources.length - 1].remove();
}
var source = doc.hyperlinkTextSources.add(text);
var dest = doc.hyperlinkURLDestinations.add(shadow.parentStory.contents.toString());
var hyperlink = doc.hyperlinks.add(source, dest);
if (charStyle = doc.characterStyles.itemByName('Hyperlink'), charStyle.isValid) {
source.appliedCharacterStyle = charStyle;
}
}
shadow.remove();
}
app.doScript(clipboard2hyperlink, ScriptLanguage.JAVASCRIPT, [], UndoModes.FAST_ENTIRE_SCRIPT, 'Hyperlink by Clipboard');