Automating file saves by type

Have a problem? A question? This is the place for answers from other Express users.
Post Reply
allenwatson
Posts: 34
Joined: 2005-10-05 15:05:51
Location: Portland, OR
Contact:

Automating file saves by type

Post by allenwatson »

I have several hundred Word documents. I want to open one, save it to Location A as a Word document, Location B as a PDF, and Location C as an HTML document. I'm proficient at AppleScript.

I can script a regular save with a file type of ".doc", which results in a document Word can open (I don't care if it is actually a Word document or an RTF).

I can script a "save thedoc as "HTML" in "filepath:filename.html"", which results in an HTML file.

How do I script a "save as PDF"?

Perhaps a more generic question (maybe a separate one) is, what are the valid file types that can be specified after "as"? "HTML" seems to work. What else does?
allenwatson
Posts: 34
Joined: 2005-10-05 15:05:51
Location: Portland, OR
Contact:

No answer?

Post by allenwatson »

:?: Should I interpret the fact that no one has answered this question to mean that there is no way, in AppleScript, Perl, or Automator, to automate a "save as PDF" function? :?:
allenwatson
Posts: 34
Joined: 2005-10-05 15:05:51
Location: Portland, OR
Contact:

More info

Post by allenwatson »

I've discovered I can at least cause NWE to save as PDF by using the "Do Menu Macro" command and giving it the string "Save as PDF". The drawback is that I cannot give an argument such as the name of the file or the folder to use in saving, so the dialog box appears asking for a file name and location.

Also, I am finding that if I tell NWE in AppleScript to "save thedoc as 'RTF' in a-file-path-with-name", I get an error saying NWE cannot (for instance) save "285.doc" in "285.doc". No explanation, just can't do it. So I cannot get normal file saving, or saving as HTML, programmed in a script either.

I want to be able to have my script prompt for a file name and then automatically save the three different formats in three different folders. Anybody have any ideas?
Anne Cuneo
Posts: 164
Joined: 2004-09-23 02:15:46
Location: Switzerland
Contact:

Post by Anne Cuneo »

In order not to let you do all the answering to your own questions yourself (':P'), I would like to point out that you can also save any file as pdf through the print dialogue. As I am no expert at scripting, that's the path I use mostly.
As for saving automatically in two or more different places, if you find a way, I wish you would tell me, I have been longing for an automatic security save since Nisus Classic...
Anne
allenwatson
Posts: 34
Joined: 2005-10-05 15:05:51
Location: Portland, OR
Contact:

More of same

Post by allenwatson »

I'm quite disappointed that no one from Nisus has chimed in with a solution, a partial solution, or at least a "Sorry, no way to do that yet."

Of course, Anne, I know about saving to PDF via the Print dialog. The File menu "Save as PDF" just avoids the step of having to select the PDF popup in the Print dialog box; it goes straight to the Save dialog. That's what I have been using, but I'm looking for more complete automation of the three separate saves I need to do.

I've tried using the following macro, but after the first save (in which I have to select "Microsoft Word document", select the folder and type in the file name, then click the Save button...all steps I want to automate), nothing happens; the second and third save do not occur. Is there some kind of "pause" I must insert?

Code: Select all

Copy
New
Paste
Save
Save as PDF
Save as
rmark
Official Nisus Person
Posts: 428
Joined: 2003-02-11 10:49:05
Location: Solana Beach, CA
Contact:

Post by rmark »

Rather than give a quick "off the cuff" response, we thought we'd think about it over the weekend.

Here's what our engineering staff has to say on the matter.
I don't think this is doable, except by a difficult workaround.

The AppleScript command he is using doesn't work the way I think it should:

save the doc as "HTML" in "filepath:filename.html"

This command completely ignores the 'as "HTML"' portion and decides what type to save as based on the filename extension. That all happens in Cocoa code before we ever get hold of it. In addition the 'Save as PDF...' command really does an export rather than a true 'Save As...'. So .pdf is not an extension that we recognize and it ends up being saved as a plain text file.

The workaround involves using what's called 'UI scripting'. So the script would look something like what I include below. However, UI scripting has always been flaky for me and I've never gotten it to work correctly. The user would have to make sure to turn on the "Enable access for Assistive Devices" checkbox in the Universal Access system preference pane.

Code: Select all

set fname to "autosavedfile2"
tell application "Nisus Writer Express"
    set theDoc to document 1
    save theDoc in "Users:username:Desktop:" & fname & ".doc"
    set theDoc to document 1
    save theDoc in "Users:username:Desktop:" & fname & ".html"
    activate
    Do Menu Macro with macro "File:Save As PDF..."
end tell
delay 2

tell application "System Events"
    set theProc to item 1 of (application processes whose name is "Nisus Writer Express")
    set theDialog to item 1 of (windows of theProc whose name is "Save As PDF")
    set theTextField to item 1 of (text fields of theDialog)
    set value of theTextField to (fname & ".pdf")
    set saveButton to item 1 of (buttons of theDialog whose name is "Save")
    click saveButton
end tell
I hope this helps a bit.
Write On!
Mark Hurvitz
Nisus Software Inc.
Post Reply