Applescript - simple MS Word script

March 2, 2009 at 11:29:40
Specs: Macintosh
I'm trying to write a script that will automatically type

Facts


Issue


Holding


Rationale

when I hit a keyboard shortcut. I know some of the script commands, but I can't figure out how to tell Word to separate these words on different lines. I need the space between these words - 3 lines.

I'm in law school and I have to type this out about 5 times a day and it would be really nice to press shift-command-B and have it all inserted for me. It has to be in Italics like that also. Can anyone help me out? Is this even possible? Thanks.


See More: Applescript - simple MS Word script

Report •


#1
March 2, 2009 at 13:59:24
*BUMP*, anyone?

Report •

#2
March 2, 2009 at 14:12:50
Have you tried to create a macro?

Tools - Macro - Record New Macro

A small window should pop-up
In the small window there should be two buttons, press "Keyboard'

In the next window, in the lower left you should see:
"Press new shortcut key"

The cursor should be blinking in the box below.

To Assign: Ctrl-Alt-X
(This particular key combination is un-assigned on my computer)

Simply hold down the CTRL Key the ALT key and the letter X key all
at once.

If it tells you the key is assigned to another function, then it's
your choice to change Your key sequence or to overwrite the function.

Press the "Assign" button.
Your key combination will jump from the "Press New Shortcut Key" box
to the "Current Keys" Box.

Press the Close button.

This is where you start to record your Macro.
There should be a small box on the screen, with two buttons.
A "stop" button and a "pause" button.

Now with your mouse, press the Italic's button on the tool Bar, it looks like a tilted upper case I.

Type the word:

Facts

Press the Italic's button

Press the Enter key
Press the Enter Key
Press the Enter Key

Press the Italic's button
Type the word:

Issue

Press the Italic's button

Press the Enter key
Press the Enter Key
Press the Enter Key

Press the Italic's button
Type the word:

Holding

Press the Italic's button

Press the Enter key
Press the Enter Key
Press the Enter Key

Press the Italic's button
Type the word:

Rationale

Press the Italic's button

Now press Ctrl-HOME keys and your cursor should return to the top left of the screen over the letter "F" in Facts.
Now press the "END" key, and your cursor goes to the end of the line, after the word "Facts".

Were done.

With your mouse, click the "Stop" button on the little box.
The little box disappears.

Next time you need it, just press Ctrl-Alt-X and the magic happens.

Don't worry if you mess things up the first time, just start from the beginning and do it again.

MIKE


Report •

#3
March 2, 2009 at 14:21:02
I probably should have mentioned this is MS Word 2008, and there is no option in Tools-->Macro for "record new Macro." I can't figure out how to record a new Macro in Word 08. I agree this would be a lot easier and I would prefer to do that.

Report •

Related Solutions

#4
March 2, 2009 at 14:24:28
I'm pretty sure the new MS Word doesn't support VB for applications, meaning you can't record any new Macros. I guess I'm stuck writing a script or typing this out every time, unless anyone has any other ideas. Can anyone help me write the script?

Report •

#5
March 2, 2009 at 15:08:05
Save your self.....

http://www.openoffice.org/

(It uses macros and it's free)

MIKE


Report •

#6
April 30, 2009 at 15:50:31
If you know VB you can convert it to AppleScript using MS
VB to AppleScript. The below will set the text to your
clipboard when run, but won't style it (no italics) AS doesn't
know anything about text styling, applications that are driven
by AS do however. MS is a PITA to script. here's the finder
script, just paste into a script editor doc and save as
application. After you click on the application you've made,
put your cursor at the proper insertion point of a word doc
and command+v (paste) et voila.
--beginning of script
set fiHR to "Facts" & return & return & return & return &
"Issue" & return & return & return & return & "Holding" &
return & return & return & return & "Rationale"

set the clipboard to fiHR
--end of script two lines only


Report •

#7
April 30, 2009 at 16:08:19
This article was written almost a year ago.

Has the promise of the return of VBA not been fulfilled?

http://arstechnica.com/apple/news/2...


Report •

#8
April 30, 2009 at 16:21:29
Still no VBA.

here's another script, this one creates a new Word Doc
(which you may not need, just have to change to insertion
point and then run it:
--begin script
set fiHR to "Facts" & return & return & return & return &
"Issue" & return & return & return & return & "Holding" &
return & return & return & return & "Rationale"
tell application "Microsoft Word"
activate
create new document
set myRange to create range active document start 0
end 0
set content of myRange to fiHR
set myRange to change end of range myRange by a
story item ¬
extend type by selecting

set name of font object of myRange to "Arial"
set italic of font object of myRange to true

end tell
--end script


Report •

#9
April 30, 2009 at 17:26:58
Mistake...

Report •

#10
April 30, 2009 at 18:59:51
The application script worked perfectly, and it's a great solution. The perfectionist in me is curious to see if there's any way to make a script, bind it to a hotkey in word, so that I don't have to externally open an application to do this. I tried to script posted by damondidit above and it looks great, but it keeps finding an error with the "0" after "end" and "of" after "change end." It won't compile in script editor. I don't really know VB at all and I only know basic script commands here, so I'm not sure how to fix it.

I can't thank everyone enough for the help. I figured this thread would never get answered and you guys already made my life so much easier. Please don't spend too much time on this if you're busy. I really appreciate all the help. Thanks.


Report •

#11
May 1, 2009 at 10:26:02
Dave the "end 0" line needs to be moved up to follow the
"start 0", so they are on the same line. This sites msg box
chopped the line to make it appear as it is two lines I should
have used the ¬ code. So that line should end as follows:

start 0 end 0

cool?

There are also other add-on apps like Red Sweater Software
(FastScripts $15) or Quicksilver (free more techie, but
bitchin) which will allow you to setup things of the keyboard
shortcut nature.
I've posted compiled/yet open applications to my site for
your use.

http://www.solutionarts.net/freebie...
http://www.solutionarts.net/freebie...
you can open these in Script editor before launching them to
check for any nasties that befall our Windows brethren.


Report •

#12
May 1, 2009 at 11:59:19
@damondidit

Try putting < pre> </pre > around your code so it holds the formatting used in the editor you wrote it in.

(I've added a space fore and aft so the < pre> </pre > shows up in the text of this post. )

You can type in the < pre> </pre > or just click on the pre icon above the message box.

This was done inside < pre> </pre >:

Line 1
 Line 2
      Line 3
      Line 4
 Line 5
Line 6


Report •

#13
May 4, 2009 at 08:20:18
thanks DerbyDad, will do.

--first script

set fiHR to "Facts" & return & return & return & return & 
"Issue" & return & return & return & return & "Holding" & 
return & return & return & return & "Rationale"

set the clipboard to fiHR 

--end of sript

--second script

set fiHR to "Facts" & return & return & return & return & "Issue" & return & return & return & return & "Holding" & return & return & return & return & "Rationale"
tell application "Microsoft Word"
	activate
	create new document
	set myRange to create range active document start 0 end 0
	set content of myRange to fiHR
	set myRange to change end of range myRange by a story item ¬
		extend type by selecting
	
	set name of font object of myRange to "Arial"
	set italic of font object of myRange to true
	
end tell

a bit more legible for Script Editor.


Report •

#14
May 4, 2009 at 08:37:48
perfect, thanks a lot. just wondering how to change the insertion point. i took out the "create new document" line.

Report •

#15
May 4, 2009 at 10:57:16
it's all pretty convoluted.

Tell me how this doc is being created? is it a template, that
has text before and after the desired insertion point? or is it
at the point and time of insertion the physical end of the
document (wether or not more text will be added later).

I will have limited time this week as I gotta pay the bills, but
you can check out the Word Dictionary in Script Editor, or
M$ 564 page Word 2004 AppleScript document.

sorry,
d


Report •

#16
May 4, 2009 at 18:27:07
I'm not sure what you mean by template, but I basically want to bind this script to a shortcut in Word so I am able to just hit that shortcut while typing and insert it into my text. The first script you posted is good for that as it puts this on the clipboard, but then if I need to copy and paste something else it will just erase that.

Report •


Ask Question