Re: Command line printing

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Rob Daly [MSFT] (rdaly_at_online.microsoft.com)
Date: 12/10/04


Date: Fri, 10 Dec 2004 10:14:34 -0800

If you're looking for a simple way to print from the desktop in Word X
through an applescript, the following script would work (this is just code
for the printing). By the way - command line is not an option.

tell application "Microsoft Word"
    activate

    set theDoc to <enter mac path to the file here> --something like "Mac OS
X: users: me: documents: mydoc"

    do Visual Basic "application.displayalerts - wdAlertsNone"
    do Visual Basic "activedocument.printout"
    do Visual Basic "application.displayalerts - wdAlertsAll"

    quit saving no

end tell

Here is some explanation of why I wrote it this way:

I use visual basic commands because the Office suite "print" command in
version X Applescript with bring up the Print Dialog - I'm guessing you do
not want that. Also - I'm guessing that you are trying to get a fast
printout without any app interaction. That is why I quit word at the end. It
also explains why I used the visual basic "displayalerts" method. In the two
lines that use it, I am telling word to (1) accept all alert defaults and
(2) show all alerts again - this is because I need to set it back to show
all alerts afterwards as it won't get set back otherwise. Why do I do this?
so that margin warnings won't stop the script.

In order to really get this script to approach something that runs from the
desktop, you would need to make it into a droplet script where you drag the
file you want to print onto the script and that then becomes the variable
"theDoc". I won't go into how to do that in Applescript here as I'm sure
others are eeking to tell you ;)

-- 
Rob Daly
Macintosh Business Unit
Word Test
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not send email directly to this e-mail address. It is for
newsgroup purposes only.
Find out everything about Microsoft Mac Newsgroups at:
http://www.microsoft.com/mac/community/community.aspx?pid=newsgroups
Check out product updates and news & info at:
http://www.microsoft.com/mac
"John McGhie" <john@mcghie.name> wrote in message 
news:BDC40A69.C978%john@mcghie.name...
> The lpr function simply pumps strings out of the defined port.  You need 
> to
> ensure the strings are what your printer understands.
>
> To do this, you need to call Word's print routine to hand the document off
> to the OS X PDF converter.
>
> Use AppleScript to create a running instance of Word, then use the 
> GetObject
> function to return it to your script, and the application.printout 
> function
> to print the list of documents you provide.
>
> I'm not an AppleScript person, but there are plenty here who can tell you
> how to do that.
>
> You do need to create an instance of Word, but you can create a hidden
> instance that the user is not aware of and you have total control over.
>
> I am told that the AppleScript support in Word 2001 sux, and that calling 
> an
> application within a guest operating system is rather an extreme measure.
> Had you thought of purchasing a copy of Word 2004?  AppleScript support is
> vastly improved in 2004.
>
> Cheers
>
>
> On 18/11/04 10:42 PM, in article
> 6f147b4b.0411180342.31183798@posting.google.com, "Ihab Badr"
> <ihabbadr@netscape.net> wrote:
>
>> Folks,
>>
>> I am using Office 2001 on OS X.2
>> Is there a way to print a WORD document from the command line?
>> Using lpr does not work as I suspect lpr does not understand the WORD 
>> format.
>>
>> Thanks in Advance
>
> -- 
>
> Please reply to the newsgroup to maintain the thread.  Please do not email
> me unless I ask you to.
>
> John McGhie <john@mcghie.name>
> Consultant Technical Writer
> Sydney, Australia +61 4 1209 1410
> 


Relevant Pages

  • Re: AppleScripting
    ... Paul Berkowitz wrote: ... >> I'm a beginner AppleScript programmer, and I'm looking for a way to ... I need a command that opens the Labels ... So to stop the script from waiting I introduced a deliberate ...
    (microsoft.public.mac.office.word)
  • Re: Time Machine: Spit!!!
    ... I'd like a script that'd dive down a directory tree recursively and move ... If you want to see an AppleScript version as well then I could knock one up in the next day or so when I have a bit of spare time. ... As for data types - I just develop patiently one small bit at a time and looking carefully at the results. ... Standard way to do recursion in AppleScript is to define a function that calls itself. ...
    (uk.comp.sys.mac)
  • Re: Forcing downloaded Word documents to open at page width
    ... If the AppleScript keystroke does not work ... You gave me this script a few months back and it has been a godsend. ... The information you gave in this thread about triggering a keyboard shortcut ... set view type of view of active window to page view ...
    (microsoft.public.mac.office.word)
  • Re: Question for Paul and other AppleScripters
    ... I'm writing a script to do batch edits on my contacts. ... > objects or use a reference to to loop through the list of selected contacts to ... If you want to use AppleScript, ... enable whose clauses on lists. ...
    (microsoft.public.mac.office.entourage)
  • Re: Auto loading applescripts?
    ... That's the biggest lack of AppleScript compared to VBA ... there is currently no mechanism of any type to embed a script inside a ... as there is in Entourage. ... Office macros enabled a whole plethora of viruses, ...
    (microsoft.public.mac.office.word)