Exporting paragraphs from Quark doc

Discuss AppleScripting for QuarkXPress 10, 9 & 8 (and before)
Post Reply
IanB
Posts: 3
Joined: 03 Aug 2007, 05:31

Exporting paragraphs from Quark doc

Post by IanB » 02 May 2008, 11:24

Hi,

The following script gives the result I require apart from the fact that I need the prices to be comma separated.
This script is extracting all the prices from a page but in one line which is no good for importing into Excel.

This is the result I get . . .
"Filename.qxp, 12.76 Ex-VAT1414.99217.02 Ex-VAT25414.997.06 Ex-VAT86.17 Ex-VAT768.08 Ex-VAT7949.9929.9925.53 Ex-VAT29Was 12.99*11Was 19.99*1810.97 Ex-VAT1212.76 Ex-VAT1412.76 Ex-VAT1414.9921.27 Ex-VAT2424.99254.9912.9911.06 Ex-VAT125.53 Ex-VAT68.398.298.157.2511.7514.9912.76 Ex-VAT1418.750.997.9912.896.4979.999.998.51 Ex-VAT919.9917.02 Ex-VAT19"

Any help would be appreciated.

This is the script . . .

tell application "QuarkXPress Passport"
activate

set theName to name of document 1
set thePath to file path of document 1
end tell


tell application "QuarkXPress Passport"
tell document 1


set textOne to (every paragraph of every story where it contains ("" as string))
end tell
end tell


set thisString to theName & ", " & textOne as string

IanB
Posts: 3
Joined: 03 Aug 2007, 05:31

Exporting paragraphs from Quark doc

Post by IanB » 02 May 2008, 12:35

OK, this script gives me what I want, but I'm not sure how I can write the result to a csv file
Anyone got any ideas please?

tell application "QuarkXPress Passport"
activate

set theName to name of document 1
set thePath to file path of document 1
end tell


tell application "QuarkXPress Passport"
tell document 1


set textOne to (every paragraph of every story where it contains ("" as list))
end tell
end tell


--set thisString to theName & ", " & textOne as text





set thisString to textOne

Emma
Posts: 657
Joined: 07 Jul 2004, 08:43

Exporting paragraphs from Quark doc

Post by Emma » 06 May 2008, 03:33

how about something like (this is typed straight into reply box, no time to test in Applescript!)

repeat with i from 1 to count of paragraphs
set textOne to textOne & "," and paragraph i
end repeat

- obviously you'd have to build in your filter for prices. My idea is that you build up your file, adding in the commas you'll later use when you import into Excel.

BTW, doesn't 'every paragraph of every story where it contains "" ' give you too many paragraphs? i.e. it's looking for stories which contains "" rather than paragraphs.

Can you tell us more about what you're trying to achieve?

IanB
Posts: 3
Joined: 03 Aug 2007, 05:31

Exporting paragraphs from Quark doc

Post by IanB » 06 May 2008, 03:59

Hi Emma,

Thanks for your response.

What I'm trying to achieve is this . . .

I have numerous Quark pages which have prices in various boxes on the page, (not consistent), and need to extract all the prices and write them into a .csv file. The only thing consistent throughout the prices is of course the .

Cheers,

Ian.

Emma
Posts: 657
Joined: 07 Jul 2004, 08:43

Exporting paragraphs from Quark doc

Post by Emma » 06 May 2008, 04:21

I just ran your script on a file of mine, and it worked fine - the paragraphs are separated by returns, which I imagine is more useful than commas, assuming you want each item on a new line in Excel?

Aha! I suspect your paragraphs don't contain returns? So it's like a price box with just '9.99' in it? In that case you are going to have to add your own into the string, which will mess up your nice elegant one-line script.

Try this:

set textOne to ""
tell application "QuarkXPress"
tell document 1
set theName to name
set thePath to file path

repeat with i [b]from 1 [b]to (count [b]of [b]every story)
[b]tell story i
[b]repeat [b]with j [b]from 1 [b]to (count [b]of [b]every paragraph)
[b]if paragraph j [b]contains "" [b]then
[b]set textOne [b]to textOne & return & paragraph j
[b]end [b]if
[b]end [b]repeat
[b]end [b]tell
[b]end [b]repeat
[b]end [b]tell
[b]end [b]tell


[b]set thisString [b]to theName & ", " & textOne [b]as string

I takes longer than your script - if your files are huge, that could be a problem. I've taken out the 'activate' because it's rarely useful, and tidied up your 'tells'.


[b]Slightly off the original question:

Once the prices are in Excel, I imagine they aren't much use until they are related to a product? If you're doing a lot of this sort of thing, you should investigate XCatalog from Emsoftware. This enables you to put a 'link' onto prices, which relates each one to a product code. You can then export all the linked prices, along with their codes in one click. And (and this is the nice bit) update them instantly if the customer returns the excel file with new prices!

Post Reply

Return to “QuarkXPress 8, 9 & 10: AppleScript”