Any AppleScripters?

M

Mark

Hi
This should be really easy ... but I can't do it!
I want to assign a hotkey so I can, via AppleScript, open a new
document from an existing template (like the File > Project Gallery >
My Templates > choose-and-click)

Any ideas?
 
P

Paul Berkowitz

This should be really easy ... but I can't do it!
I want to assign a hotkey so I can, via AppleScript, open a new
document from an existing template (like the File > Project Gallery >
My Templates > choose-and-click)

Actually, this (the hot key part) is not something that can be done just be
AppleScript at the moment. Word does not have its own script menu with a
mechanism for adding keyboard shortcuts, like Entourage does. You have to
run scripts either as self-standing script applications (applets), which
you'd double-click or put into the dock and single-click, or as a .scpt
script from the system's script menu. The system's script menu also does not
have a hotkey mechanism. You'd need to get a 3rd-party utility such as iKey,
QuicKeys, or DragStuff, that can set up hotkeys for scripts and other apps.
(I think in this case only for script applications, which are always slow to
launch, like any application. But I might be wrong - perhaps one or the
other of them can also load and run a .scpt script, which would be faster.
Check out DragStuff in particular.)

Similarly, there's currently no way to use Tools/Customize to assign a
Keyboard Shortcut (hotkey) to a script: that - and a script menu - is
something you should request here for a later Word version. However, if you
wrote it as a VBA macro, you _could_ assign a hotkey that way.

I'm assuming what you want is to specify one particular template as the one
to make a new document from? You'd just press the key combo and get that
document opening? (You'd need a different key combo for each such template.
Lots of key combos to remember.) If you actually want to "choose-and-click"
from different templates in My Templates, why not just use the built-in
combo cmd-shift-P to open the Project Gallery? Yes, there's that one more
step of clicking My Templates, but that's not such a big deal.

There's no way to script opening just My Templates in the Project Gallery
itself, I don't think. There is something called "GUI Scripting" - a
not-very-reliable method of simulating clicking and menu-choosing by
AppleScript in Panther and Tiger, which works for Cocoa applications and
some Carbon apps - but doesn't work at all for MS Office apps (except menu
items, only, in Entourage; nothing at all in Word).

If from all this, there's something you'd like to do that does involve a
script or macro, say which, an maybe there's something that can be done.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
M

Mark

Actually, this (the hot key part) is not something that can be done just be
AppleScript at the moment.

Yeah - I know this ... I'm just not very good at expressing myself! I
wanted to trigger the script using Quickeys ... sorry for not stating
this in the original message.
I'm assuming what you want is to specify one particular template as the one
to make a new document from?

That's it - or rather, have several set up - one for lesson plans, one
for apparatus lists (guess my job?)
(You'd need a different key combo for each such template.
Lots of key combos to remember.)

Quickeys would let me use a SoftKey palette; I open a palette of
templates, then hit the button for the one I want.
... why not just use the built-in cmd-shift-P to open the Project
Gallery? Yes, there's that one more
step of clicking My Templates, but that's not such a big deal.

Oh, I agree! It's just that I like other ways of doing stuff - I spent
longer trying to get a PowerPoint Action to work than it would have
taken to do it manually! However once done it woul be easier!

For instance I could eventually set up Automator to run these scripts
on the day I wanted, opening other documents to go with it (resource
files and such). It would take longer than impatience demands, but if
it ran at, say, 5pm Wednesday everything would be waiting.

It's a pity just double-clicking on the template doesn't open a new doc.

I suppose opening a read-only doc would have a similar effect, but then
I'd have to dismiss several "you can't save this" files.

Hmmmm I could also "Save As..." with the new name of the file (usually
Apps+date)

Too many ideas? Maybe, but thanks for the advice.....
If from all this, there's something you'd like to do that does involve a
script or macro

A script - for the reasons outlined, but no hassles.

My script started with something like

tell application "Microsoft Word"
activate
open as document "LessonPlansTemplate.dot"
end tell

But it fails (sorry about bold: I can't find out how to turn it off in Unison!)
 
P

Paul Berkowitz

A script - for the reasons outlined, but no hassles.

My script started with something like

tell application "Microsoft Word"
activate
open as document "LessonPlansTemplate.dot"
end tell

OK. Unintuitively, perhaps, 'open as document' actually opens the template
itself (like when you double-click it on a Mac), when you give it the full
path to the template. 'as document' here means "so you can edit it, like you
do with a document". This command derives form the equivalent VBA command
which is needed more on Windows where double-clicking makes a new doc, as
you know: it's harder there to open the template itself!

What you want is something like this:

tell application "Microsoft Word"
set p to get default file path file path type user templates path
set templatePath to p & ":My Templates:LessonPlansTemplate.dot"
make new document with properties {attached template:templatePath}
end tell


This will work in SP 2: I have a vague memory that there was a bug
previously. Check out 'get default path' command. 'user templates path' is
the Templates folder, but missing the final ":" colon we expect for folders
in AppleScript: you have to add on the colon and "My Templates" (with final
colon) plus the template name to get the path. Then you make a new document
using the 'attached template' property: "name" of the template (as the
dictionary and user guide say) really means the full path unless the
template itself is already open itself of registered in Add-Ins.

Get the Word AppleScript Reference form the MacTopia
website/Resources/Developer/AppleScript. It's a big help when trying to
script Word.

Attach a keyboard shortcut to this script in QuicKeys, and you should be
good to go.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
M

Mark

OK. Unintuitively, perhaps, 'open as document' actually opens the template
itself (like when you double-click it on a Mac)

I see
What you want is something like this:
<snip >

Thank you. I'll give it a go later and get back to you if necesssary.
There's a bit of a "do" this weekend (sis-in-law getting engaged) so it
may be a while!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top