Don't know where to begin

Discussion in 'Mac Programming' started by kenglade, Jul 3, 2009.

  1. kenglade macrumors 6502

    Dec 20, 2008
    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
  2. mysterytramp macrumors 65816


    Jul 17, 2008
    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.

  3. kenglade thread starter macrumors 6502

    Dec 20, 2008
    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?

  4. GorillaPaws macrumors 6502a


    Oct 26, 2003
    Richmond, VA
    You might want to take a look at Apple's Intro to AppleScript Language Guide which has a section on Commands.
  5. kenglade thread starter macrumors 6502

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

Share This Page