Copy link to clipboard
Copied
As the title says, how do i clear the clipboard while scripting with copy/paste functions?
Because i am affraid for crashes because too much items are on the copy buffer
Thanks.
Copy link to clipboard
Copied
deselect all and copy
app.activeDocument.selection = null;
app.copy();
Copy link to clipboard
Copied
CarlosCanto​,
Carlos, when I run this snippet from ESTK in AI CC 2015.3 (Mac) AI crashes.
I've tried it on a new, blank document and other documents. Any ideas?
I need to purge the system clipboard.
Copy link to clipboard
Copied
hmm, I see that when you don't have anything selected the Copy function is not available in the UI. That might be the issue but it's not making the app crash on Windows and it is clearing the clipboard.
try
app.executeMenuCommand('copy') to see if works
why purge? too much data? or trying to delete "sensitive" data?
can you use keyboard maestro? maybe other apps can copy nothing
is copying something else an option?
Copy link to clipboard
Copied
app.executeMenuCommand('copy') also crashes on Mac.
I use a series of script/macros to copy-and-paste elements from "Layout" templates to "Tray" templates, in preparation for lasering. On very rare occasions there is NOTHING in the "Layout" template so the correlating "Tray" position should be left blank. The problem is, since there is still residual content in the clipboard it is pasted into the "Tray" template in the space that should be left blank. I thought purging the clipboard might fix that problem.
Here is the actual script used for capturing the "Layout" artwork. I've commented out the portion that crashes AI.
//~ Test for text objects then copy content.
testForText();
function testForText() {
var doc = app.activeDocument;
app.executeMenuCommand("selectall");
var sel = doc.selection;
if (sel.length == 0) {
alert("There's nothing selected");
//~ app.copy();
//~ aDoc.close(SaveOptions.DONOTSAVECHANGES);
} else {
var textFrameDetected = false;
for (var i = 0; i < doc.selection.length; i++) {
if (doc.selection.typename == "TextFrame") {
textFrameDetected = true;
}
}
if (textFrameDetected) {
alert("A text frame was detected! Release the hounds!");
} else {
app.copy();
aDoc.close(SaveOptions.DONOTSAVECHANGES);
}
}
!}
Yes, I could use Keyboard Maestro to purge the system clipboard. It would just mean breaking the script into two scripts (I think).
You've caused me to think, maybe I could just copy a temporary object to the clipboard, in the event the selection is blank, then delete said object in the "Tray" template. Seems tedious for something that may occur once a year.
By the way, thanks to Silly-V​ for the "Test for Text" snippet!
Copy link to clipboard
Copied
copying something then deleting it might be your best bet, no choice. Tedious is the norm scripting illustrator 😕
Copy link to clipboard
Copied
This is working for me:
var aDoc = app.activeDocument;
app.executeMenuCommand("deselectall");
var alignLayer = aDoc.layers["Align"];
var print = aDoc.layers["FINGERPRINT"];
var alignObj = aDoc.pathItems["FingerprintAlign"];
try{
if (print.pageItems.length = 1){
print.pageItems[0].selected = true;
}
}
catch (e){}
alignLayer.visible = true;
alignLayer.locked= false;
print.locked = false;
print.selected = true;
try {
alignObj.selected = true;
//move selection to "FINGERPRINT" layer
alignObj.move(print, ElementPlacement.PLACEATEND);
app.executeMenuCommand("group");
}
catch (e) {
alert("the layer doesn't exist");
// do whatever you want
}
alignLayer.visible = false;
app.executeMenuCommand("deselectall");
The "FingerprintAlign" object is then auto-deleted in "Traying". Turns out this was just a slight modification to what I was already doing in other scenarios.
Carlos, thanks for all your contributions here. You keep me inspired to learn this stuff.
Copy link to clipboard
Copied
you're welcome ray, glad to help
Find more inspiration, events, and resources on the new Adobe Community
Explore Now