Skip to main content
Participant
Feb 1, 2010 9:31 PM UTC
Answered

Script for deleting objects on pasteboard

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

Harbs.
Harbs.Correct answer
Legend
Feb 1, 2010 9:34 PM UTC

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

while(obj=objs.pop()){

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

}

Harbs

8 replies

Marc Autret
Legend
Feb 2, 2010 12:00 AM UTC

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

Translate
Inspiring
Jan 6, 2013 4:30 PM UTC

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

Translate
Harbs.
Legend
Jan 6, 2013 7:36 PM UTC

This is simpler:

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

while(obj=objs.pop()){

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

}

Harbs

Translate
Harbs.
Harbs.Correct answer
Legend
Feb 1, 2010 9:34 PM UTC

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

while(obj=objs.pop()){

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

}

Harbs

Translate
noteon
Participant
Sep 21, 2023 10:52 PM UTC

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.

Translate
Inspiring
Aug 16, 2025 9:30 AM UTC

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

Translate