Having trouble saving the name

Here is my script, I’ve been working on it for weeks and I demonstrate it tommorrow to my boss and his boss. I place the word files into a target folder. When I start the script it asks me to choose the folder, and then It will get all of the customer word documents (approx 106 but I will test with ten) and open each one individually, get specific text from the word doc and put it into a Quark document to create a two-sided advertising piece specific to each customer.

Right now, it brings up a dialog box at the end to name the file. What I really need is for it to go ahead and name the file for me. But so far I can’t get it to work.

  • In one of the Quark Text boxes the client code name appears. it is Text Box 3 of page 1.

  • What I need is to change the name of the Quark Document to “8529_” and “story one of text box 3.” This will result in a name like 8529_ABC. But I keep getting messages like – 8529 doesn’t understand the save command–

  • Here is another alternative. strFile is the name of the word doc. It is the name I want, but it ends in .doc. Is there a way to set the name of “strFile” to the new name of the quark document but change the extention from “.doc” to “.qxd”. This will produce a result of changing 8529_abc.doc to 8529_abc.qxd

on run
	set strLogFileName to "SearchLog.txt"
	set strLogFilePath to "~/" & strLogFileName
	-- Erase log file's contents
	do shell script "cat /dev/null > " & strLogFilePath
	-- Allow user to choose folder to search from
	set aFolder to choose folder with prompt "Choose Folder to Search..."
	set strSearchValue to "8529"
	-- Grab the directory's contents
	set lstFolderContents to list folder aFolder without invisibles
	
	-- Repeat through the folder's content
	repeat with i from 1 to (count of lstFolderContents)
		set strFile to ((aFolder & item i of lstFolderContents) as string) as alias
		-- Get the info for the file we processing
		set recFileInfo to info for strFile
		-- Check to see if the item we are processing is a folder
		if (not folder of recFileInfo) then
			set strFileName to name of recFileInfo
			if (strFileName contains strSearchValue) then
				-- Append to our log the path of the file in MAC PATH format
				do shell script "echo \"" & (strFile as string) & "\" >> " & strLogFilePath
			end if
		end if
		tell application "TextEdit"
			open strFile
			tell strFile
				set theText to text of document 1 of application "TextEdit"
			end tell
		end tell
		tell application "TextEdit"
			close document 1
			make new document
		end tell
		tell application "TextEdit"
			set text of document 1 of application "TextEdit" to theText
		end tell
		tell application "TextEdit"
			tell document 1
				set firstPart to (get every paragraph whose first word is "Pay")
				set secondPart to (get every paragraph whose first word is "Whatever")
				set thirdPart to (get every paragraph whose first word is "clientname")
				set fourthPart to (get last paragraph)
				
			end tell
		end tell
		
		--this opens the Quark file and flows the text into the text box
		tell application "Finder"
			activate
			open document file "test_file.qxd" of folder "Desktop" of folder "me" of folder "Users" of startup disk
		end tell
		tell application "QuarkXPressâ„¢"
			tell document 1
				set story 1 of text box 1 to firstPart
				set story 1 of text box 2 to secondPart
				set story 1 of text box 3 to thirdPart
				delete (characters 1 thru 11) of story 1 of text box 3
				
			end tell
		end tell
		
		--this opens the Quark file and flows the text into the text box
		tell application "QuarkXPressâ„¢"
			tell document 1
				tell page 2
					set story 1 of text box 1 to fourthPart
					set story 1 of text box 2 to thirdPart
					set story 1 of text box 3 to thirdPart
					delete (characters 1 thru 11) of story 1 of text box 3
				end tell
			end tell
		end tell
		tell application "TextEdit"
			close document 1 saving no
		end tell
		
		--this action locates the Quark file opened above for Quark to access
		tell application "Finder"
			activate
			open document file "Test_file.qxd" of folder "Desktop" of folder "me" of folder "Users" of startup disk
		end tell
		
		--this action opens a dialog box for the user to name the file. Then it saves the file in the appropriate folder and closes it
		tell application "QuarkXPressâ„¢"
			activate
			get document 1
			set doc to document 1
			display dialog ("save doc as") default answer "8529_" with icon note
			set nom to text returned of result
			save doc in ("Macintosh HD:Users:me:Desktop:FileTarget:" & nom)
			close document 1
		end tell
		
		
	end repeat
end run

tell application “QuarkXPressâ„¢”
activate
get document 1
set doc to document 1
display dialog (“save doc as”) default answer “8529_” with icon note
set nom to text returned of result
save doc in (“Macintosh HD:Users:me:Desktop:FileTarget:” & nom)
close document 1
end tell

What’s the class of “doc”? If it’s a string, not a doc ref, your “save doc” will fail. Could you just save document 1 or set doc to a reference to document 1?

Here is the script I have been trying.

tell application "Finder"
			activate
			open document file "Test_file.qxd" of folder "Desktop" of folder "dskipworth" of folder "Users" of startup disk
		end tell
		
		--this action opens a dialog box for the user to name the file. Then it saves the file in the appropriate folder and closes it
		tell application "QuarkXPress"
			activate
			get document 1
			set theName to every word of story 1 of text box 3 of page 1 as string
			save document 1 in ("8529_" & "theName")
		end tell
	end repeat
end run

This works

Save document 1 in ("8529_")

but when I try

Save document 1 in (8529_" & "theName")

I get this message in the compiler

"Can't make every word of text flow 1 of «class TXTB» 3 of «class page» 1 of application \"QuarkXPress\" into type string."