Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to clear clipboard

Explorer ,
May 23, 2013 May 23, 2013

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.

TOPICS
Scripting
10.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
May 23, 2013 May 23, 2013

deselect all and copy

app.activeDocument.selection = null;

app.copy();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 22, 2019 Jul 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2019 Jul 22, 2019

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 22, 2019 Jul 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2019 Jul 22, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 23, 2019 Jul 23, 2019

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 23, 2019 Jul 23, 2019
LATEST

you're welcome ray, glad to help

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines