count every picture box that contains certain image file Quark 4.11

Hi all,

I want to count every picture box that contains certain image file. I know the name of the file. I’ve tried the following code:


tell application "QuarkXPress� 4.11"
	activate
	tell document 1
		set HowManyTestsTIFFS to count (every picture box whose name = "Test1.tiff")
		display dialog "There are: " & HowManyTestsTIFFS & " file(s)."
	end tell
end tell


However, the result is always 0 (zero), even though there are picture boxes that cointains “Test1.tiff”.

What am I doing wrong?

Thanks for any help,
Paff :?:

The names of the picture boxes are only going to return something meaningful if you have actually named the boxes from a script previously. Did you name the boxes? I suspect what you actually want to do is to find all the picture boxes that contain a specific image. If that is the case, try this code (adjusting the path to the image, of course):

set the_image to "path:to:Test1.tiff"
tell application "QuarkXPress? 4.11"
    activate
    tell document 1
        set HowManyTestsTIFFS to count of (picture boxes whose file path of image 1 of it = (the_image as alias))
        display dialog "There are: " & HowManyTestsTIFFS & " file(s)."
    end tell
end tell

Jon

If you want to use your original script, run this script first which will set the name of all picture boxes that have an image to the name of that image:

tell application "QuarkXPress? 4.11"
    tell document 1
        set picture_box_refs to object reference of picture boxes
        repeat with this_picture_box in picture_box_refs
            try
                tell this_picture_box
                    set name to (my get_name(file path of image 1))
                end tell
            end try
        end repeat
    end tell
end tell

on get_name(the_path)
    set old_delim to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {":"}
    set the_name to (text item -1 of (the_path as string))
    set AppleScript's text item delimiters to old_delim
    return the_name
end get_name

After this is run, you should be able to successfully run your original script.

Jon

Yes, I do want to count only those picture boxes that contain specific image. I didn’t name the boxes.

I copied the code:


set the_image to "WaterX:Users:paff:Desktop:Test1.tiff"
tell application "QuarkXPress™ 4.11"
	activate
	tell document 1
		set HowManyTestsTIFFS to count of (picture boxes whose file path of image 1 of it = (the_image as alias))
		display dialog "There are: " & HowManyTestsTIFFS & " file(s)."
	end tell
end tell

and ran the script. I got an error. Below’s the error message:


QuarkXPress™ 4.11 got an error: every picture box of document 1 whose file path of image 1 = alias "WaterX:Users:paff:Desktop:Test1.tiff" doesn't understand the count message.

The file is on the desktop. It was not moved when the script was running. I’m running MacOS X 10.3.2 however I don’t think that os version has something to do with it.

Was the file on the desktop when it was imported into the picture boxes in QXP? If it was in some other location when imported, and then you moved it to your desktop to run the script without updating the document, there will be no picture boxes that match and you may receive the error you mentioned. Is this the case?

Jon

Hi Paff
I had always problems with “whose” in QXP

Try this (Tested and works with OS 9.2 and QXP 4.0)


set the_image to alias"WaterX:Users:paff:Desktop:Test1.tiff" 
tell application "QuarkXPress™ 4.11" 
   activate 
   tell document 1 
      repeat with i from 1 to count of picture boxes
			         if file path of image 1 of picture box i = the_image then
				            set HowManyTestsTIFFS to HowManyTestsTIFFS + 1
			          end if
		        end repeat
      display dialog "There are: " & HowManyTestsTIFFS & " file(s)." 
   end tell 
end tell 

jonn8 - yes, the file was on the desktop when I imported it into quark’s picture boxes and it was not moved from the desktop.

debloem - when I copied and pasted your code into script editor I got the error message saying that “The variable HowManyTestsTIFFS is not defined.” So I added the line defining the variable and setting it to 0 (zero). The code is as follows:

set the_image to alias "WaterX:Users:paff:Desktop:Test1.tiff"
tell application "QuarkXPress? 4.11"
    activate
    tell document 1
        repeat with i from 1 to count of picture boxes
            if file path of image 1 of picture box i = the_image then
                set HowManyTestsTIFFS to 0
                set HowManyTestsTIFFS to HowManyTestsTIFFS + 1
            end if
        end repeat
        display dialog "There are: " & HowManyTestsTIFFS & " file(s)."
    end tell
end tell

However, I still can’t count all picture boxes that contain “Test1.tiff”, even though there are 4 picture boxes out of 5 that contain the image. When I ran the script it returns 1 (one) in dialog box. In Event Log I can see that it finds all 5 picture boxes. The output of a log file is:


tell application "QuarkXPress� 4.11"
	activate
	count every picture box of document 1
		5
	get file path of image 1 of picture box 1 of document 1
		alias "WaterX:Users:paff:Desktop:Test1.tiff"
	get file path of image 1 of picture box 2 of document 1
		null
	get file path of image 1 of picture box 3 of document 1
		alias "WaterX:Users:paff:Desktop:Test1.tiff"
	get file path of image 1 of picture box 4 of document 1
		alias "WaterX:Users:paff:Desktop:Test1.tiff"
	get file path of image 1 of picture box 5 of document 1
		alias "WaterX:Users:paff:Desktop:Test1.tiff"
	display dialog "There are: 1 file(s)."
		{button returned:"OK"}
end tell

How can I make AS to do what I want it to do - to count properly all picture boxes with “Test1.tiif” in them?

-Paff

I can confirm that all of the code I posted above works on Mac OS X 10.3.2 and QuarkXPress 4.1.1 running in Classic. Here is the combination of the second code I posted and your original code along with a “choose file” call at the beginning to allow you to just run the code without modification (select the image in question):

set the_image to (my get_name(choose file))
tell application "QuarkXPress? 4.11"
    activate
    tell document 1
        set picture_box_refs to object reference of picture boxes
        repeat with this_picture_box in picture_box_refs
            try
                tell this_picture_box
                    set name to (my get_name(file path of image 1))
                end tell
            end try
        end repeat
        try
            set HowManyTestsTIFFS to count of (picture boxes whose name = the_image)
        on error the_error
            display dialog the_error buttons {"OK"} default button 1 with icon 0
            return
        end try
        set the_plural to "s"
        if HowManyTestsTIFFS = 1 then set the_plural to ""
        display dialog "The image "" & the_image & "" was placed " & HowManyTestsTIFFS & " time" & the_plural & " in this file." buttons {"OK"} default button 1 with icon 1
    end tell
end tell

on get_name(the_path)
    set old_delim to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {":"}
    set the_name to (text item -1 of (the_path as string))
    set AppleScript's text item delimiters to old_delim
    return the_name
end get_name

Jon

jonn8 the script works great! You’re my GOD! I need to start worshipping you. :wink:

Thanks for the help!
-Paff

Hi Paff,
you are right. I forgot to paste the "set HowManyTestsTIFFS to 0 " from my script to my message. :oops:
But you had to put it before the repeat statement. Otherway in each loop, the value of HowManyTestsTIFFS returns to 0 . That’s why you get this value of 1.
I think it will work for you too now (if you want to try once).

Happy to see that the script of jonn8 works great for you. His approach of your problem is different of mine and it’s interesting.