Skip to content

Instantly share code, notes, and snippets.

@grefel
Created November 18, 2015 15:39
Show Gist options
  • Save grefel/f1424c3a73f34e75b789 to your computer and use it in GitHub Desktop.
Save grefel/f1424c3a73f34e75b789 to your computer and use it in GitHub Desktop.
Read clipboard contents with InDesign
try {
var pstwp = app.clipboardPreferences.preferStyledTextWhenPasting;
app.clipboardPreferences.preferStyledTextWhenPasting = false;
var doc = app.documents[0];
var typoQ = doc.textPreferences.typographersQuotes;
doc.textPreferences.typographersQuotes = false;
var tf = doc.textFrames.add();
tf.insertionPoints[-1].select();
app.paste();
var clipboard = tf.parentStory.contents;
$.writeln(clipboard);
}
catch (e) {
alert (e + " \nLine " + e.line);
}
finally {
app.clipboardPreferences.preferStyledTextWhenPasting = pstwp;
doc.textPreferences.typographersQuotes = typoQ;
}
@grefel
Copy link
Author

grefel commented Nov 18, 2015

Ugly but works. Note the typographersQuotes, which are important for tabular/excel data.

@grefel
Copy link
Author

grefel commented Dec 15, 2015

found a better solution from harbs:

https://forums.adobe.com/thread/2022613

alert(GetClipboard());  
function GetClipboard(){  
    var clipboard;  
    if(File.fs == "Macintosh"){  
        var script = 'tell application "Finder"\nset clip to the clipboard\nend tell\nreturn clip';  
        clipboard = app.doScript (script,ScriptLanguage.APPLESCRIPT_LANGUAGE);  
    } else {  
        var script = 'Set objHTML = CreateObject("htmlfile")\r'+  
        'returnValue = objHTML.ParentWindow.ClipboardData.GetData("text")';  
        clipboard = app.doScript(script,ScriptLanguage.VISUAL_BASIC);  
    }  
    return clipboard;  
}  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment