Need help: QXPress script to replace red color with black

Hi there!

This is my first post here and I am a complete beginner with Applescript. So every help is welcome…
And sorry for stupid questions I’ll probably raise.

The issue:
I have a (huge) list of QuarkXPress documents that need to be changed. The files contain only red lines and I need to have them in black.
So I’d like to put the files into a folder and let QXP work through it (btw: I can upload the QuarkXPress Passport 7.1 dictionary of course). It should open the file, delete color “red” and replace it with color “black”. Then choose the object tool, select all, modify and de-select “disable output”. Once that is done QXP shoudl save the file (either based on the original file name (into new folder) or just replace the existing (can make copy in advance).

Honestly I have no clue about the effort needed to get a script running for that. I just started reading through some AS starter books and hope that this practical “example” helps me to get into it quicker.
Thanks a mill to everybody reading through it and thinking about it. :cool:

Best regards, Markus

mpeschen,

It sounds like what you want to do is change the color of each object then surpress them from printing then save as in a different directory. This is alittle more involved than just a line or to of code. You should try write your code step by step.

open one of your docs and try to just get the color changed then then see if you can figure out how to do that to all the objects once you have achieved that move on to the suppressions then to opening and saving.

I’m sure that many including myself will help you when you get stuck.

hope this is helpful

MM

Hi mp

And Welcome to whole world of applescript frustration!! (stick with it! its worth it though)

Don’t want to help you to much but this should get you started if not it will point you in a good direction:

tell application "QuarkXPress Passport"
	tell document 1
		set the color of every line box to "Black"
	end tell
end tell

What do you mean “disable output” is it like mcgrailm says “suppress output” more info needed on that one!
For more info on quark scripting check out the apple events guide in the documents folder in your quark folder.

good luck

Hey again!

Big thx for your replies on my question!! Of course I do not expect somebody to do my job but it’s absolutely great to have found a forum like this.

@ pidge1: great tip with that qxp applescript documentation. that was something totally missing so far. now I have some stuff to read.

To answer your question: Yes, I a pretty sure that “suppress output” is what I mean. Working on a localized version (german) so sometimes I might fail to translate properly… But to make it clear: “suppress output” must not be checked ebfore saving the item. I just had to add this because when you go to modify (apple+m) after selecting all, the box “suppress output” seems to be half ticked (I guess for parts of the document it’s active). This step is just to make sure that this box is not checked in the end.

Again thx you guys and gals for assistance! Will now read through that Script documentation for QXP.

Cheers, Markus

Me again,
what I found out so far (to be honest: what I collected so far…):

tell application “QuarkXPress Passport”
tell document 1
set the color of every line box to
“Black”
set suppressed_items to object reference of every generic box whose suppress printing is true
repeat with
this_item in suppressed_items
tell this_item
set suppress printing to false
end tell
end repeat
end tell
end tell

This runs pretty smooth besides the fact that I have to have the docuemnt open (what gives me an unwanted question at QXP startup: use XPress or Project Settings. Would like to ALWAYS use Project Settings). So the next step for me is to get that kind of automated (run through a folder).
Cheers

Model: iMac (Intel)
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi mp

To open a load of files in a folder you need to create a script which relies on recursion.
this can be tricky but you should find examples on this forum.
your best bet to start with would be a simple repeat loop similar to what you have in your current script that repeats
thru files that you throw on a droplet then opens each one and applies your script to it.
you will need an “on open” handler and to save your script as an application…

hope this helps a bit

in your open command to Quark you can tell it to use doc prefs:

open TheDoc use doc prefs yes

To process a folder of quark files you need to decide if you want a drag and drop, a folder action, or to just point the script to the folder. I would suggest pointing the script to the folder at least to until you are done developing the main body of the script, then working up the other methods once the script is working.
To point the script to a folder you can use something like this:

set processFolder to choose folder with prompt "Choose a folder that contains images to process"
set targetFolder to choose folder with prompt "Choose a folder to save processed images"
tell application "Finder" to set listImages to (files of entire contents of processFolder whose file type is "JPEG" or name extension is "jpg") as alias list

Of course you would need to change the file type and extensions to those of the Quark documents.

Wow! Thank you for your answers! Actually my script looks like that:

tell application “QuarkXPress Passport”
tell document 1
open use doc prefs yes
set the color of every line box to
“Black”
set suppressed_items to object reference of every generic box whose suppress printing is true
repeat with
this_item in suppressed_items
tell this_item
set suppress printing to false
end tell
end repeat
end tell
try
set
thepath [b] to [/b] “iMac_Admin2:Users:Admin2:Desktop:Test:”
save document 1 in (thepath & “TestOutputA.qxp”)
[color=blue]end try

[color=blue]end tell[/color]

Still questions open:
1st: how to set the new name (output) to the same as the original file?
2nd: @ Jerome: how do I get this ‘use doc prefs yes’ implemented here? Actually there’s the automation missing (still launching qxp by double-clicking file and then starting script). I tried to adapt your info (line 3) but can’t see a result yet. Have to implement the automatism first.

BTW: I’d like to point the script to a folder. The things I need to do with QXP is (hopefully) an one time action. Once The templates are adjusted there are other tasks waiting :wink:

Can’t thank you enough!!

mpeschen,

what you have is good I have condensed it alitte and add the name of the file to the save line I also show here how to open the file using the document prefs “theFiles” will need to be a list of alias files
I was not able to test this so please let me know if it works ok I did however test the name thing


	repeat with aFile in theFiles
		tell application "QuarkXPress"
			open file aFile use doc prefs yes
			tell document 1	
				set the color of every line box to "Black"
				set suppress printing of every generic box to false
				try
					set thepath [color=blue] to "iMac_Admin2:Users:Admin2:Desktop:Test:"
					save (thepath & name)
				end try		
			end tell
		end tell
	end repeat

mm

hi mcgrailm,
yes, ideed, you condensed the script a bit. cool! unfortunately I was not yet able to get it fully running. I guess “theFiles” needs to be set. Assuming that thsi should point to a folder I just added 1 line in front of your script:
set theFiles to “iMac_Admin2:Users:Admin2:Desktop:701-800 Kopie:” (this is where the original templates are)
When running the script I get an error (translated): žQuarkXPress" received an error: The file žsome object" could not be found.
This is not clear to me. Was I wrong in pointing to a folder? There is no object called “some object”!

markus

mpeschen,

in a previous part of this post Jerome shows how to get a list of alias files you need to set “theFiles” in a similar manner so that “theFiles” is a list of alias files is that making sense ?

MM

hey,
sorry for bugging you. that’s what I have now. does not give me an error but also no output (quark does not seem to do anything besides launching).

set processFolder to choose folder with prompt "Choose a folder that contains images to process"
tell application "Finder" to set theFiles to (files of entire contents of processFolder whose file type is "QuarkXPress Project Template" or name extension is "qxp") as alias list
repeat with aFile in theFiles
	tell application "QuarkXPress Passport"
		open file aFile use doc prefs yes
		tell document 1
			set the color of every line box to "Black"
			set suppress printing of every generic box to false
			try
				set thepath to "iMac_Admin2:Users:Admin2:Desktop:Test:"
				save (thepath & name)
			end try
		end tell
	end tell
end repeat

I must have made something wrong again or I just don’t get it. I will asap look for a good trainings course for AppleScripting. :confused:

slight mod my fault sorry

tell application “Finder”
set processFolder to choose folder with prompt “Choose a folder that contains images to process”
set theFiles to files of processFolder
end tell
repeat with aFile in theFiles
tell application “QuarkXPress”
open (aFile as alias) use doc prefs yes
tell document 1
set the color of every line box to “Black”
set suppress printing of every generic box to false
try
set thepath [color=blue] to “iMac_Admin2:Users:Admin2:Desktop:Test:”
save (thepath & name)
end try
end tell
end tell
end repeat

File Type for Quark 6.5 is XPRJ (project) or XPRT (template)
File Kind is QuarkXPress Project File or QuarkXPress Project Template
File Creator is XPR3

For some reason Quark is not saving an extension on my computer, but you should be able to just use the file type and eleminate the extension, so the finder line would be:

set processFolder to choose folder
tell application "Finder" to set theFiles to (files of entire contents of processFolder whose file type is "XPRJ" or file type is "XPRT") as alias list

The advantage of doing it this way is that it will build a list of only quark documents from the folder and any sub folders within the one that you choose.

Probably that was already too much for me for today. Getting more and more confused. Since restarting my machine and reopening my scripts (of course I made some kind of step-by-step-save) I wonder why the script has changed itself (line 7, 9, 10):

tell application “Finder”
set processFolder to choose folder
tell application “Finder” to set theFiles to (files of entire contents of processFolder whose file type is “XPRJ” or file type is “XPRT”) as alias list
end tell
repeat with aFile in theFiles
tell application “QuarkXPress Passport”
open (aFile as alias) given «class KPRF»:yes
tell document 1
set the color of every «class LNBX» to “Black”
set «class supr» of every «class GNBX» to false
try
set thepath to “iMac_Admin2:Users:Admin2:Desktop:Test:”
save (thepath & name)
end try
end tell
end tell
end repeat

Although I don’t think this is the reason for failing here I can hardly understand why I am not able to change the lines back. They are not accepted anymore. Hope you get what I mean.
What happens is that I am saked for the folder > select > QXP launches
That’s it. At this point it stucks.
Is there a problem in line 7? Did remove the brackets from “aFile as alias” and the first time it worked out (so QXP launched and processed the files. Saving did not work but that’s something for later). Don’t know why. Since then QXP did not process the files again :confused:

I have to finish this project for today. Unfortunately I don’t have QXP at home so I won’t be able to test until tomorrow.
But if somebody has a good idea just let me know…

ahh a fun quark bug if you close the script then open quark then open the script you code will look normal again

mm

Hi MP

Try this:

set processFolder to choose folder with prompt "Choose a folder that contains images to process"
tell application "Finder" to set theFiles to (files of entire contents of processFolder whose file type is "XPRJ") as alias list
repeat with aFile in theFiles
	tell application "QuarkXPress Passport"
		open aFile use doc prefs yes
		set x to name of document 1
		tell document 1
			set the color of every line box to "Black"
			set suppress printing of every generic box to false
			set thepath to (path to desktop folder) & x as string
			save in thepath
			close saving no
		end tell
	end tell
end repeat

works for me saves quark docs to the desktop, can be changed to be saved elsewhere.

Looks great! Can’t test now. No Quark on my MB :rolleyes: But will directly test when back @ work.
Just have to check back whether just dealing with qxp templates or project files also.
BTW: why does QXP call a template file “Project 1” when opening it instead keeping the original name? Could that be because the templates might have been created in a prior QXP vesion? Hope this does not kill my need to have the output named like original file.
Anyway… kind of excitedt to test the script. :stuck_out_tongue:

Templates in Quark and Indesign both give you a different name so that you do not accidently save over the template file when you create a new document file from the template.

So how to get the original filename into the saved file? Ain’t it possible to just turn off this security feature preventing from overwriting the original template? And of course the file should be saved as project template, not as project. But I guess that’s a minor issue compared to the file name thingee. Will try to find out how to adjust the file type when saving. Could somebody give me a hint regarding the names?
cheers

Edit:
To save the file as Project Template (XPRT) I think it is needed to include something like ‘save as template boolean’. But when I add this line (or adjust the existing save line) I get an error when running the script: “…could not be converted in preferred type” (error translated, sorry). Probably I try to implement that at the wrong place.

For the name thing:
The first two lines of the script create a nice list (path + filename). QXP works through this list. Is it possible to tell Quark to save each file where it came from based on that list (also using the name showing up there)?

I know, I am still asking stupid questions :stuck_out_tongue: