PDA

View Full Version : Don't know where to begin




kenglade
Jul 3, 2009, 03:34 PM
I know almost nothing about how to write apple scripts but I think I'm going to have to learn some basics.

I'm running Office 2008 for Mac on a G5 Leopard. I just switched from a PC where I was using Word 2007. Since Word 2008 does not have macros I'm lost trying to convert make two of my often-used macros.

One is to cap the first letter of a word, say "john" to make it read "John." In 2007 I wrote a macro telling the program to go to the beginning of the word, select the letter, cap and then go to the end of the word.

The other was to transpose letters, say in the word "amke" to make it read "make." (Autocorrect is one way of doing this but AC doesn't always apply). I wrote a macro so if I placed my cursor between the "m" and the "k" in "amke", the macro would move one space to the left, do a CTRL-X, go one space to the right and do a CTRL-V, then go to the end of the word.

Can anyone tell me a way to do this in script without having to learn the language? At least the commands necessary.

Many thanks



mysterytramp
Jul 3, 2009, 04:25 PM
Without Word, I don't have its scripting dictionary so I can't be the greatest help.

But there is one thing you can try now ...

Open Word and have a document up on the screen with text in the document.

Open Script Editor. It's inside the AppleScript folder inside Applications.

Click the button in the upper left corner called "Record"

Go back to Word. Using only the keyboard, select one letter, cut, hit the left arrow, hit paste (transpose the two characters).

Now return to Script Editor.

If Word is all it's cracked up to be, you should have your script.

If nothing's there, it means Word isn't scriptable and Steve Ballmer should be forced to eat your Mac.

The capitalization routine will be a little trickier.

(Assuming the first one was successful)

Use the keyboard to move the cursor to the beginning of a word.

Select the character.

Now return to Script Editor.

You'll need to add code that will look like this (though I can't guarantee this works):

get the selection of window 1
set asciiNum to the ascii number of it
if asciiNum > 96 then
set the selection of window 1 to the ascii character (asciiNum-32)
end if

BTW, you might not find AS's performance inside Word acceptable, especially for simple character manipulation. You might want to explore something like QuicKeys or Word's own commands. Isn't there a Title case command that capitalizes the first letter of a word? Add a hotkey to that and you'll be in business.

mt

kenglade
Jul 4, 2009, 09:04 AM
Without Word, I don't have its scripting dictionary so I can't be the greatest help.

But there is one thing you can try now ...

Open Word and have a document up on the screen with text in the document.

Open Script Editor. It's inside the AppleScript folder inside Applications.

Click the button in the upper left corner called "Record"

Go back to Word. Using only the keyboard, select one letter, cut, hit the left arrow, hit paste (transpose the two characters).

Now return to Script Editor.

If Word is all it's cracked up to be, you should have your script.



Many thanks for your reply. I'm going to try this and see what happens. FYI, when I was writing the macro in Word 2007, I discovered I couldn't use actual letters because those would be used in the macro activitation. IOW, if I set the macro to transpose "e" and "l" every time I activated the macro I'd get "l" and "e". I had to record strictly keyboard movements. So let me play with it and I'll let you know.



If nothing's there, it means Word isn't scriptable and Steve Ballmer should be forced to eat your Mac.

The capitalization routine will be a little trickier.

(Assuming the first one was successful)

Use the keyboard to move the cursor to the beginning of a word.

Select the character.

Now return to Script Editor.

You'll need to add code that will look like this (though I can't guarantee this works):

get the selection of window 1
set asciiNum to the ascii number of it
if asciiNum > 96 then
set the selection of window 1 to the ascii character (asciiNum-32)
end if

BTW, you might not find AS's performance inside Word acceptable, especially for simple character manipulation. You might want to explore something like QuicKeys or Word's own commands. Isn't there a Title case command that capitalizes the first letter of a word? Add a hotkey to that and you'll be in business.

mt

You're absolutely right about Title Case. That will do the job. What I'm trying to do, though, is to automate the process of highlighting the word, activating Title Case and jumping to the next word. So far I have not been able to find a Word 2008 shortcut key for highlighting a word, or going to the beginning of a word.

What I obviously lack is a knowledge of how to write commands in AS. Can you recommend a book for newbies containing only the basics?

Ken

GorillaPaws
Jul 4, 2009, 09:36 AM
What I obviously lack is a knowledge of how to write commands in AS. Can you recommend a book for newbies containing only the basics?

Ken[/I]

You might want to take a look at Apple's Intro to AppleScript Language Guide (http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html) which has a section on Commands (http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW59).

kenglade
Jul 4, 2009, 11:23 AM
You might want to take a look at Apple's Intro to AppleScript Language Guide (http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html) which has a section on Commands (http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW59).

Good link. Many thanks. It will take me awhile to examine and absorb but it looks like a great starting place.