Created
November 18, 2015 15:39
-
-
Save grefel/f1424c3a73f34e75b789 to your computer and use it in GitHub Desktop.
Read clipboard contents with InDesign
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
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
Ugly but works. Note the typographersQuotes, which are important for tabular/excel data.