Copy link to clipboard
Copied
I recieved this code from an awesome community member ... but its for a mac user. I'm trying to show a friend with a PC how to use it... is there another way to code 'getting clipboard contents' without it being system specific?
Would calling out Windows instead of Macintosh and Finder work? I'm also not familiar with applescript - does that make a difference with PCs?
I'm still searching around to try and find java for clipboard contents ... but wanted to see if someone here had a solution.
function Main() {
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;
}
If clipboard contents is always a string, you can make a temp text frame in your active document, read the contents, and delete the frame. Not sure that would be any faster. What's the use of the clipboard contents? That might help us steer you in better direction.
var getClipboard = function() {
try { var temptf = app.activeDocument.textFrames.add({geometricBounds: ["0pt","0pt","20pt","50pt"]}); } catch(e) { return ""; }
temptf.insertionPoints[0].select();
app.paste();
var contents = temptf.
...
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I'm still searching around to try and find java for clipboard contents
Do you mean Java or JavaScript?
The JavaScript code you posted checks for the system name via File.fs and if it is Mac OS uses AppleScript to get the clipboard and if it’s not uses VisualBasic. This sends an alert with the result:
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;
}
Copy link to clipboard
Copied
awesome, so the visual_basic langauge is for a PC ... I've been having some issue with the original code lagging quite a bit, sometimes if i toggle between files it will reset and work quickly, other times it is delayed almost 30 seconds. so i wasnt sure if there was simpler code to aquire clipboard contents.
Copy link to clipboard
Copied
If clipboard contents is always a string, you can make a temp text frame in your active document, read the contents, and delete the frame. Not sure that would be any faster. What's the use of the clipboard contents? That might help us steer you in better direction.
var getClipboard = function() {
try { var temptf = app.activeDocument.textFrames.add({geometricBounds: ["0pt","0pt","20pt","50pt"]}); } catch(e) { return ""; }
temptf.insertionPoints[0].select();
app.paste();
var contents = temptf.parentStory.contents;
temptf.remove();
return contents;
}
Copy link to clipboard
Copied
Hi Brian, your first line is missing the properties object end brace I think it should be this?
var temptf = app.activeDocument.textFrames.add({geometricBounds: [0,0,20,50]});
Copy link to clipboard
Copied
Thaks, Rob. Also forced "pts" so we don't blow out the page if we're on inches. Need more coffee.
Copy link to clipboard
Copied
I use the string for a couple different scripts I run in InDesign;
I also assign shortcuts to the scripts for even quick use.
Copy link to clipboard
Copied
OK, try my updated code above. I guess I don't get, though, how CTRL+V is unsuitable for your needs.
Copy link to clipboard
Copied
Works! thank you so much! so far I'm not experiencing the delay I was having before so thats super awesome!
yes, ctrl+v works fine but the scripts minimize amount of clicks and contain multiple functions:
if theres only 1 or 2 instances in a file obviously i'm not saving loads of time, but i'm creating files with 50+ images/graphics and over 100 form fields and have the scripts with multi function so i'm just ctrl+c and then run my script shortcut it saves me LOOOOOADS of time 🙂