Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 3, 2009, 03:34 PM   #1
kenglade
macrumors 6502
 
Join Date: Dec 2008
Don't know where to begin

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
kenglade is offline   0 Reply With Quote
Old Jul 3, 2009, 04:25 PM   #2
mysterytramp
macrumors 65816
 
mysterytramp's Avatar
 
Join Date: Jul 2008
Location: Maryland
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
__________________
What looks large from a distance, close up ain't never that big.
mysterytramp is offline   0 Reply With Quote
Old Jul 4, 2009, 09:04 AM   #3
kenglade
Thread Starter
macrumors 6502
 
Join Date: Dec 2008
Quote:
Originally Posted by mysterytramp View Post
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
kenglade is offline   0 Reply With Quote
Old Jul 4, 2009, 09:36 AM   #4
GorillaPaws
macrumors 6502a
 
GorillaPaws's Avatar
 
Join Date: Oct 2003
Location: Richmond, VA
Quote:
Originally Posted by kenglade View Post
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 which has a section on Commands.
GorillaPaws is offline   0 Reply With Quote
Old Jul 4, 2009, 11:23 AM   #5
kenglade
Thread Starter
macrumors 6502
 
Join Date: Dec 2008
Quote:
Originally Posted by GorillaPaws View Post
You might want to take a look at Apple's Intro to AppleScript Language Guide which has a section on Commands.
Good link. Many thanks. It will take me awhile to examine and absorb but it looks like a great starting place.
kenglade is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
I really dont know where to begin Walter Bell Mac Programming 9 Aug 26, 2011 04:07 PM
iAd help - I know what but I don't know where to put the code. Mitch1984 iPhone/iPad Programming 0 Mar 14, 2011 04:58 AM
I'm so lost I don't know where to begin. (Yet another newbie thread) krye Mac Programming 26 Jul 25, 2008 01:04 AM
Help! I love apple but dont know where to begin! darylkotze Buying Tips and Advice 3 May 4, 2008 03:42 PM
I don't know where to put this... but I need help with Keynote + outputting to a TV Chone Mac Applications and Mac App Store 0 Nov 11, 2006 11:15 AM


All times are GMT -5. The time now is 07:48 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC