script to delete all items on the pasteboard

Hmm. That should’ve worked. Are any items grouped across the page boundary?

No, none of the items were grouped at all. That snippet just deleted everything, including the items on the page.

Please make a new document with one item in the pasteboard and one on the page. I would be interested to know what is returned from this statement:

tell application "Adobe InDesign CS3"'s document 1 to {all page items, page items's parent}

The fallback solution is to negatively check each item against the page area.

set withoutList to {}

tell application "Adobe InDesign CS3"'s document 1
	set theBounds to page 1's bounds
	set thelist to page items
	repeat with anitem in thelist
			tell anitem to if not (geometric bounds's item 1 ≥ theBounds's item 1 and ¬
				geometric bounds's item 2 ≥ theBounds's item 2 and ¬
				geometric bounds's item 3 ≤ theBounds's item 3 and ¬
				geometric bounds's item 4 ≤ theBounds's item 4) then
				set withoutList's end to its contents
			end if
	end repeat
	delete withoutList
end tell

Marc,

I ran this code and nothing happened.


	tell myDocument
		select {all page items, page items's parent}
	end tell

This was the result:


tell application "Adobe InDesign CS6"
	activate
	get active document
		--> document id 4
	select {all page items of document id 4, parent of every page item of document id 4}
		--> {}
end tell
Result:
{}

Marc,

Your other suggestion is basically what I’m doing. I am selecting each page item and getting its geometric bounds and determining if the object is on the pasteboard. The problem I’m having is that I cannot select each item. I am getting an error on some of them: error number -1728 – this error is “Can’t get «script».”

I’m going to try some troubleshooting this afternoon. Scripting is not my full-time job (unfortunately), so I have to work on it in my spare time.

I will keep you posted on my progress.

Thanks!

You altered the code I provided. It’s expected that the result of my one-liner is a list, which is not selectable. Please try both sets of code as written. Something has to be returned from the instruction, and I can’t help you without knowing what this is”even if it’s an error message.

Marc,

I’m so sorry! I thought I had the gist of what your code was doing and so I made some changes. So I ran this code:


tell application "Adobe InDesign CS6"'s document 1 to {all page items, page items's parent}

tell application "Adobe InDesign CS6"'s document 1
	set theBounds to page 1's bounds
	set thelist to page items
	repeat with anitem in thelist
		tell anitem to if not (geometric bounds's item 1 ≥ theBounds's item 1 and ¬
			geometric bounds's item 2 ≥ theBounds's item 2 and ¬
			geometric bounds's item 3 ≤ theBounds's item 3 and ¬
			geometric bounds's item 4 ≤ theBounds's item 4) then
			set withoutList's end to its contents
		end if
	end repeat
	delete withoutList
end tell

and got this result:


tell application "Adobe InDesign CS6"
	get all page items of document 1
		--> {rectangle id 219 of spread id 198 of document id 8, rectangle id 218 of spread id 198 of document id 8, rectangle id 217 of spread id 198 of document id 8}
	get parent of every page item of document 1
		--> {spread id 198 of document id 8, spread id 198 of document id 8, spread id 198 of document id 8}
	get bounds of page 1 of document 1
		--> {0.0, 0.0, 11.0, 8.5}
	get every page item of document 1
		--> {rectangle id 219 of spread id 198 of document id 8, rectangle id 218 of spread id 198 of document id 8, rectangle id 217 of spread id 198 of document id 8}
	get item 1 of geometric bounds of rectangle id 219 of spread id 198 of document id 8
		--> 2.631944444444
	get item 2 of geometric bounds of rectangle id 219 of spread id 198 of document id 8
		--> -4.763055555556
Result:
error "The variable withoutList is not defined." number -2753 from "withoutList"

I’m sorry Marc. I had missed the line where you set withoutList to {}. I added it and it worked!!! Thank you so much!!

Hello karensink

This list is fair enough to give us a tool allowing us to grab the posted script without missing something.

No need to copy-paste which is prone to errors. Just click the button [Open this Scriplet in your Editor:] to get . the complete script in our Editor.

Using this tool is a good way to spare asker’s and helper’s time.

Yvan KOENIG running El Capitan 10.11.6 in French (VALLAURIS, France) jeudi 25 aout 2016 13:51:09

Thank you, Yvan!! I was not aware of this tool. I will definitely use it in the future.

I found a way to select all the items on the pasteboard of the first spread. I noticed that items which are fully on the pasteboard have a parent page property of nothing. I tried using:


set ThePasteboard to every page item whose parent page is nothing

but this always resulted in an empty list. So I made a list of every page item whose parent page has a class of page (i.e. has a parent page). Then I made a new list of every page item that is not in the first list.


tell application "Adobe InDesign 2020"
	tell document 1
		tell spread 1
			set ThePageArea to every page item whose class of parent page is page
			set AllPageItems to every page item
			set ThePasteboard to {}
			repeat with i from 1 to (count AllPageItems)
				set ThisPageItem to item i of AllPageItems
				if ThisPageItem is not in ThePageArea then
					set the end of ThePasteboard to ThisPageItem
				end if
			end repeat
			select ThePasteboard
		end tell
	end tell
end tell

I tried missing value but this also resulted in an empty list. It may be a bug or limitation but the workaround does the job. Indesign can select a list when the list contains references to page items. The command “select ThePasteboard” (ThePasteboard is the list variable) results in all the objects on the pasteboard of spread 1 being selected.

Hi, David. Your version is significantly newer than mine or the OP’s, so the parent page property may not have existed when this question was posted, and the iteration in your code appears unnecessary; if something should be returned but isn’t, the culprit could be that the statement isn’t explicit enough and needs a get. Try these statements:

tell application "Adobe InDesign 2020"'s document 1
       tell spread 1
	   select (get page items whose parent page is nothing)
	 -- select (get page items whose parent page's class is nothing)
	 -- select (get page items whose parent page is not page)
	   end
	   end

Hi Marc, I’m happy to be corrected on this. Your solution sounds reasonable but in testing, the code did not work for me. For example, the following still results in an empty list:


tell application "Adobe InDesign 2020"
	tell document 1
		tell spread 1
			--set ThePasteboard to every page item whose parent page is nothing
			set ThePasteboard to (get page items whose parent page is nothing)
		end tell
	end tell
end tell

What is returned by :


tell application "Adobe InDesign 2020"
	tell document 1
		tell spread 1
			 (get parent page of every page items)
		end tell
	end tell
end tell

It may be helpful to build a valuable filter.

You must know that some applications don’t have implemented the whose filter.
You may try with the where filter which is recognized sometimes when the whose one isn’t.

Here is an example borrowed from AppleScript User Guide showing how to use it.

tell application "Finder"
    it --result: application "Finder" (target of tell statement)
    set myFolder to path to home folder
        --result: alias "Leopard:Users:myUser:"
    files in myFolder --result: a list of Finder document files
    files in myFolder where name of it contains "AppleScript"
    (* result: document file "AppleScriptLG.pdf" of folder "myUser"
        of folder "Users" of startup disk of application "Finder"}*)
    files in myFolder where name contains "AppleScript" -- same result
    every file in myFolder whose name contains "AppleScript" -- same result
    every file in myFolder where name of it contains "AppleScript" -- same result
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 9 avril 2020 12:01:04

Thanks Yvan, I tried using “where” instead of “whose”, I even tried:


set ThePasteboard to (get page items where its parent page is nothing)

but it didn’t make any difference.

By the way, the AppleScript you provided results in a list of parent pages, some members of which are nothing. So Indesign can see them but just can’t list them like we would expect. Indesign supports AppleScript very well and can handle “whose”, as demonstrated in the code above that is part of my workaround:


set ThePageArea to every page item whose class of parent page is page

This is why I think it’s just a bug, limitation or oversight in Indesign’s AppleScript support. But we often find these in our travels! The workaround works fine for now.

It also applies for parent page. If you ask for the parent page of an item on the pasteboard, it returns nothing.

(A little bit of AppleScript history: In the beginning, AS had no missing value class, or way of representing nil. InDesign defined its own nothing property at that time. The missing value class came along later.)

Except it isn’t, unfortunately.

So, whose does not work with this nothing. But then why does the following work? Maybe someone met a similar case, and will share with us.


set thePasterboard to {}
tell application "Adobe InDesign 2020" to tell document 1 to tell spread 1
	repeat with pageItem in (page items)
		if parent page of pageItem is nothing then set end of thePasterboard to contents of pageItem
	end repeat
end tell

That’s the $64 question. It looks like a bug.