Skip to main content
Participant
February 1, 2010
Answered

Script for deleting objects on pasteboard

  • February 1, 2010
  • 2 replies
  • 5581 views

Anyone have a script that deletes all objects and text outside the page (or margins)?

Correct answer Harbs.

var objs = app.documents[0].pageItems.everyItem().getElements();

while(obj=objs.pop()){

if(obj.parent instanceof Spread){obj.remove()}

}

Harbs

2 replies

Marc Autret
Legend
February 2, 2010

See also CleanupPasteboard.js if you need extra parameters and a dialog UI:

http://www.indiscripts.com/post/2009/09/clean-up-your-pasteboard

@+

Marc

Inspiring
January 6, 2013

Unfortunately in my Indi CS6 any pasteboard and spread item is "instance of spread".

So i consider geometrical bounds:

myDocument = app.activeDocument

cur_Ruler = myDocument.viewPreferences.rulerOrigin;

with(myDocument.viewPreferences){

    rulerOrigin = RulerOrigin.spreadOrigin;}

myDocument.zeroPoint = [0,0];

aWidth = myDocument.documentPreferences.pageWidth*2+10;

var objs = app.documents[0].pageItems.everyItem().getElements();

while(obj=objs.pop()){

a_left = obj.geometricBounds[1];

a_right = obj.geometricBounds[3];

     if(a_right <0 || a_left > aWidth){obj.remove()}

}

with(myDocument.viewPreferences){

    rulerOrigin = cur_Ruler} //back to the RulerOrigin

Harbs.
Legend
January 6, 2013

This is simpler:

var objs = app.documents[0].pageItems.everyItem().getElements();

while(obj=objs.pop()){

     if(obj.parentPage == null){obj.remove()}

}

Harbs

Harbs.
Harbs.Correct answer
Legend
February 1, 2010

var objs = app.documents[0].pageItems.everyItem().getElements();

while(obj=objs.pop()){

if(obj.parent instanceof Spread){obj.remove()}

}

Harbs

noteon
Participant
September 21, 2023

I love that 13 years later, I can google how to delete everything off the pasteboard, this thread is still here, and the script still works.

Inspiring
August 16, 2025

I have tried it, but it delete page content also !