I’m working on a script which will import styles from Word manuscripts. When they are imported, however, they are somewhat messed up from the conversion (I don’t know why). So I re-apply the styles in Quark. This works fine for the first document, but doesn’t when I import the following chapters. Anyone have any ideas? Here’s the script:
tell application "QuarkXPress™ 4.11"
activate
set import styles to true
set measurements showing to false
open file "Don's HD:Desktop Folder:Pop-ups:AppleScript:CastoffTemplate"
display dialog "What is the title of the book?" default answer ""
set Title to text returned of result
tell document 1
set view scale to fit page in window --import first document
set theText to choose file with prompt "Please select the first file."
set text of text box 3 of page 1 to theText --style text of forst document
try
tell story 1 of text box 3 repeat with i from 1 to (count of paragraphs)
try
set theStyle to name of style sheet of paragraph i set style sheet of paragraph i to null
set style sheet of paragraph i to theStyle
end try
end repeat
end tell
end try (*This is the main repeat loop which imports and styles the remaining chapters repeat --here, we'll delete those empty pages caused by restyling text *)
repeat with i from (count of pages) to 1 by -1
try
if (data size of text 1 of text box 3 of page i) = 0 then
delete page i on error
exit repeat
end try
end repeat --let's find out if the last page is verso. If it isn't, add a blank page.
repeat
if (page number of page -1) mod 2 = 0 then exit repeat
make page at end delete text box 3 of page -1
end repeat --now we add more chapters
try
set Text2 to choose file with prompt "Please select the next file."
make page at end
show page -1
set story 1 of text box 3 of page -1 to Text2
on error
exit repeat
end try --style text of following documents (Here's the part that doesn't work! )
try
tell story 1 of text box 3 repeat with i from 1 to (count of paragraphs)
try
set moreStyle to name of style sheet of paragraph i set style sheet of paragraph i to null
set style sheet of paragraph i to moreStyle
end try
end repeat
end tell
end try
end repeat --This ends the main repeat loop --Now we set the title and finish tell text box 2 of every page
tell paragraph 1
set properties to {contents:Title, font:"Minion", size:"16 pt"}
end tell
end tell
end tell
display dialog "Done." buttons "OK" default button 1 with icon 1
set measurements showing to true
end tell
Thanks in advance, Don
I don’t understand what you’re trying to do here:
--style text of following documents (Here's the part that doesn't work!)
try
tell story 1 of text box 3
repeat with i from 1 to (count of paragraphs)
try
set moreStyle to name of style sheet of paragraph i
set style sheet of paragraph i to null
set style sheet of paragraph i to moreStyle
end try
end repeat
end tell
end try
Right now, you’re setting the style to null, and then setting it back.
–tet
I’m setting the styles to null, then setting them back because for some reason the text gets restyled when imported to Quark. (i.e. “body copy” imports as “body copy”, but is helvetica for some reason, so it appears in Quark with a + next to the style sheet. If some one has a suggestion for importing the styles “pure,” I’d love to hear it.
Thanks for the “code” suggestion–when I went back and looked at my original post, I was mortified! (see below for the code intact)
–Don
tell application "QuarkXPress™ 4.11"
activate
set import styles to true
set measurements showing to false
open file "Don's HD:Desktop Folder:Pop-ups:AppleScript:CastoffTemplate"
display dialog "What is the title of the book?" default answer ""
set Title to text returned of result
tell document 1
set view scale to fit page in window
--import first document
set theText to choose file with prompt "Please select the first file."
set text of text box 3 of page 1 to theText
--style text of forst document
try
tell story 1 of text box 3
repeat with i from 1 to (count of paragraphs)
try
set theStyle to name of style sheet of paragraph i
set style sheet of paragraph i to null
set style sheet of paragraph i to theStyle
end try
end repeat
end tell
end try
--This is the main repeat loop which imports and styles the remaining chapters
repeat
--here, we'll delete those empty pages caused by restyling text
repeat with i from (count of pages) to 1 by -1
try
if (data size of text 1 of text box 3 of page i) = 0 then delete page i
on error
exit repeat
end try
end repeat
--let's find out if the last page is verso. If it isn't, add a blank page.
repeat
if (page number of page -1) mod 2 = 0 then exit repeat
make page at end
delete text box 3 of page -1
end repeat
--now we add more chapters
try
set Text2 to choose file with prompt "Please select the next file."
make page at end
show page -1
set story 1 of text box 3 of page -1 to Text2
on error
exit repeat
end try
--style text of following documents
try
tell story 1 of text box 3
repeat with i from 1 to (count of paragraphs)
try
set moreStyle to name of style sheet of paragraph i
set style sheet of paragraph i to null
set style sheet of paragraph i to moreStyle
end try
end repeat
end tell
end try
end repeat
--This ends the main repeat loop
--Now we set the title and finish
tell text box 2 of every page
tell paragraph 1
set properties to {contents:Title, font:"Minion", size:"16 pt"}
end tell
end tell
end tell
display dialog "Done." buttons "OK" default button 1 with icon 1
set measurements showing to true
end tell
I’m working on a script which will import styles from Word manuscripts. When they are imported, however, they are somewhat messed up from the conversion (I don’t know why). So I re-apply the styles in Quark. This works fine for the first document, but doesn’t when I import the following chapters. Anyone have any ideas? Here’s the script:
tell application "QuarkXPress™ 4.11"
activate
set import styles to true
set measurements showing to false
open file "Don's HD:Desktop Folder:Pop-ups:AppleScript:CastoffTemplate"
display dialog "What is the title of the book?" default answer ""
set Title to text returned of result
tell document 1
set view scale to fit page in window
--import first document
set theText to choose file with prompt "Please select the first file."
set text of text box 3 of page 1 to theText
--style text of forst document
try
tell story 1 of text box 3
repeat with i from 1 to (count of paragraphs)
try
set theStyle to name of style sheet of paragraph i
set style sheet of paragraph i to null
set style sheet of paragraph i to theStyle
end try
end repeat
end tell
end try
--This is the main repeat loop which imports and styles the remaining chapters
repeat
--here, we'll delete those empty pages caused by restyling text
repeat with i from (count of pages) to 1 by -1
try
if (data size of text 1 of text box 3 of page i) = 0 then delete page i
on error
exit repeat
end try
end repeat
--let's find out if the last page is verso. If it isn't, add a blank page.
repeat
if (page number of page -1) mod 2 = 0 then exit repeat
make page at end
delete text box 3 of page -1
end repeat
--now we add more chapters
try
set Text2 to choose file with prompt "Please select the next file."
make page at end
show page -1
set story 1 of text box 3 of page -1 to Text2
on error
exit repeat
end try
--style text of following documents
try
tell story 1 of text box 3
repeat with i from 1 to (count of paragraphs)
try
set moreStyle to name of style sheet of paragraph i
set style sheet of paragraph i to null
set style sheet of paragraph i to moreStyle
end try
end repeat
end tell
end try
end repeat
--This ends the main repeat loop
--Now we set the title and finish
tell text box 2 of every page
tell paragraph 1
set properties to {contents:Title, font:"Minion", size:"16 pt"}
end tell
end tell
end tell
display dialog "Done." buttons "OK" default button 1 with icon 1
set measurements showing to true
end tell
Thanks in advance, Don
Hmmmmm. I’m not having that problem. I do have to deal with the dialog box that pops up the first time, which is tough b/c it hasn’t refreshed. Once I figure out where the “Use Existing” button is (Click and drag to force buttons to refresh) and the “Repeat for all conflicts” checkbox is, it works fine.
What version of QX and Word are you using? I’m trying this with QX 4.11 & 5.0 and Word 98.
I’ve pared down your script for testing purposes, so you might want to try the following to be sure it still addresses your problem.
tell application "QuarkXPress™ 5.0"
activate
set {oldIS, oldMS, import styles, measurements showing} to {import styles, measurements showing, true, false}
tell document 1
set view scale to fit page in window
--import first document
set theText to choose file with prompt "Please select the first file."
set text of text box 1 of page 1 to theText
--(*
try
tell story 1 of text box 1
repeat with i from 1 to (count of paragraphs)
try
set theStyle to name of style sheet of paragraph i
set style sheet of paragraph i to null
set style sheet of paragraph i to theStyle
end try
end repeat
end tell
end try
--*)
end tell
--Now we set the title and finish
display dialog "Done." buttons "OK" default button 1 with icon 1
set {import styles, measurements showing} to {oldIS, oldMS}
end tell
Luck,
–tet
You don’t need all that stuff : XPress will work for you.
First of all: make sure you got the right XTENSION filter to import word docs (i.e. “MS-Word 8 Filter” for word 98) If not, save your Word docs in a compatible version or, better, go to Quark’s Downloads site (this type of xtension is free).
Here is the point : the NAME of every style sheet must be EXACTLY the same in Word AND XPress. Import a Word doc, setting “Import style sheets” to true Then XPress will ask you for an other option: “use existing styles” or “rename document styles”, and so… You must choose “use existing styles” This way, no matter what font or color is used in Word: Word style sheets will be REPLACED by XPress style sheets (got it?).
In one word : take care of the names of style sheets !!!
Try this and if it’s not enough, I own a script that re-applies style sheets. Works well in XPress 4.1
Good Luck !
zeRafio (french scripter - bad writer)