Skip to main content
Inspiring
May 23, 2013
Question

how to clear clipboard

  • May 23, 2013
  • 1 reply
  • 11026 views

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.

This topic has been closed for replies.

1 reply

CarlosCanto
Community Expert
Community Expert
May 23, 2013

deselect all and copy

app.activeDocument.selection = null;

app.copy();

rcraighead
Legend
July 22, 2019

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.

CarlosCanto
Community Expert
Community Expert
July 22, 2019

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!


copying something then deleting it might be your best bet, no choice. Tedious is the norm scripting illustrator :/