Attempting to automate savingnew word document using user input - ms-word

I'm using Applescript and I'm having trouble getting this to work, probably because my understanding of variables is quite limited. Anyhow, this is the script I have so far:
tell application "Microsoft Word"
activate
end tell
display dialog "Input Document Name" default answer ""
set answer to text returned of result
tell application "Microsoft Word"
create new document
save document as answer
end tell
I would appreciate any help or even a redirect to a relevant post. Thanks.

You have to follow the relevant Applescript dictionaries closely, and work out what Applescript is expecting. In this case, you need "save as". If you look up "save as" in the Word applescript dictionary the first things you see are
save as document
[file name text]
Let's try to plug what you have into that. Instead of "save document as answer" you would at least need
save as document file name answer
But that is not quite enough, because "document" on its own isn't the name of anything, or a reference to any document. At this point you need to look up what "create new document" does.
create new document
(various parameters)
-> document
So what you probably need is something like
set theDocument to create new document
save as theDocument file name answer
It isn't always quite a straightforward as that, and not everything is obvious from the dictionary. For example, I do not think the dictionary tells you that when word creates a new document it typically becomes the "active document". If you knew that in all possible circumnstances, that is what Word does, you could also use
create new document
save as active document file name answer
But the first approach is IMO more robust.

Related

Does anyone know how to modify the document autoformat feature in MS Word?

I'm trying to automate applying a format to a document in Word. The Autoformat dialog has three options for Document Type: General Document; Letter; Email. I had thought that I could create a template based on the document type, but I can't find much documentation on this feature and a search of the Word folders doesn't turn up anything promising. Can anyone shed any light on this?
Thanks
Since this is StackOverflow (=programming) I'm going to assume you're looking for a way to access this via VBA (a macro). The AutoFormat "type" is set using the Document.Kind object, which takes a member of the WdDocumentKind Enum:
wdDocumentEmail 2 E-mail format.
wdDocumentLetter 1 Letter format.
wdDocumentNotSpecified 0 No format specified.
Recording a macro while applying AutoFormat gives code like this:
Selection.Document.Kind = wdDocumentLetter
Selection.Range.AutoFormat
It's not very clear to me why you'd want to use AutoFormat when setting up a template. Usually, when people take the trouble to use a template they also define a set of styles and a UI for people to use the styles...

Is it possible to attach two word file with each other?

Like in MS Excel one csv file may contain more than one sheet, Like this what I have to do is I want to keep all the theory in one word file and the programs in another word file. But I want to attach these both file with each other as a single DOC file.
Like a single DOC file contain theory as well as programs, which is open as two separate content/file.
Something close to what you want to do is the following:
In new Word Document Select your "View" Tab and then Select "Outline View".
Then Select "Show Document". The "Insert Button will now be visible.
You can now insert various documents in this document.
Unfortunately as far as I know this will have links into the original Documents which you can then open, edit and access from the new document.
Try it out and let me know!
Also, you can maybe try Microsoft One Note, I think this is probably what you looking for. See partial screen shot below for an idea.

Word 2010 additional file format

I'm not sure whether this is the best approach for this or whether I perhaps should ask the question more clearer.
What I want to do is to create an additional file output - e.g. if the user uses Word to create a description consisting of known tags, I want to be able to save this as bbcode.
Now I do have an idea of how to do this, but is there a way to say add another file format to the "Save file"-dialog box and have it run a parser and file writer, that'd read the current document and export it using known bbcode-tags (that perhaps would be adjustable from some configuration window)?
The result would be a file containing bbcode as well as the text information that the user has entered.
How would I hook up my addin to the file output dialog? Is there a way to do this? I'm not sure it's custom XML since I won't be using the XML at all.
Thanks in advance and please excuse my poor English.
Edit: after having a look at the Word 2010 AddIn-project, I figured, that I'm looking for a way to define my own "export"-format. I'd like to export the BBCode to a .txt (or even .bbcode) file. The Microsoft.Office.Interop.Word.WdExportFormat seems to have its own fixed enumeration. Is there a way to add an export-format?
There is some code for this here:
phpbb.com/community/viewtopic.php?f=17&t=395554

Path of current document in [Libre|Open]Office

How can I determine the path of the currently open document in an OpenOffice or LibreOffice document? I want to forward the path to an external application.
More specifically I want to launch an external player from impress with a video file in full-screen mode:
Shell("/usr/bin/mplayer", 2, """ -fs"" some-file-in-same-dir-as-document.mp4")
For the last parameter I would need the path to the currently opened document in order to append it. Not specifying the path results in referring to the current path (as given by the CurDir() function) which is something different.
Is there actually a good reference for LibreOffice Macros? The only relatively good (but hard to search) document I have found is "OpenOffice Macros Explained" by Andrew Pitonyak.
In the meantime I have found a feasible solution. Look here:
Sub RunSomeMovie
GlobalScope.BasicLibraries.loadLibrary("Tools")
Shell("/usr/bin/mplayer -fs ", 2, "" & Tools.Strings.DirectoryNameoutofPath(ThisComponent.getURL(),"/") & "/media/somemovie.mp4")
End Sub
to get the current document path you use this simple command:
ThisComponent.getURL()
CurDir() is simply not reliable for all OS
BTW I found that info in the Pitonyak book you cited that I didn't knew and found very precious so thanks for sharing it.
I'm working with LibreOffice 4.2.0.4 and the following Code works for me:
Dim Dir as String
GlobalScope.BasicLibraries.loadLibrary("Tools")
Dir = Tools.Strings.DirectoryNameoutofPath(ThisComponent.url, "/")
The variable "dir" contains now the path of the current document.
Document has a location only if it is saved (or opened from a saved). In addition a Form opened from within LibreOffice Base does not have by its own a location. Only the odt has a location. Hence although:
ThisComponent.hasLocation()
returns True, the location is an empty string (consider it as a bug).
To obtain the location, in such cases, you have to access the "Parent":
ThisComponent.Parent.hasLocation() (or ThisComponent.Parent.getURL())
Of course you then have to "traslate" it to readable with:
Tools.Strings.DirectoryNameoutofPath

Best way to spell check a plist?

I've got about 400 different NSString entries in my plist file. I want to spell check them. At the moment I'm having to go through, expand each entry (there's a huge amount) and select the text then do a spell check (Cmd + ;).
I really need to spell check the whole thing at once, like you would in a word document, or an excel spreadsheet. I don't mind having to manually filter out the occasional field I don't need changing. It would be quicker that way, than having to go through and select all the different strings separately.
Is there anything I can do? Or am I doing it the best way already?
Thanks
Tom
In Xcode, right-click on the file you want to spellcheck. Select "Open as->Plain text file".
From there, you should be able to spellcheck the whole plist.