Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Apple Script question

Apple Script question
Thread Tools
Fresh-Faced Recruit
Join Date: Sep 2005
Status: Offline
Reply With Quote
Sep 13, 2005, 02:16 AM
 
I'm doing the following over and over again and I'd like to automate it:

1. hit "return" and wait about 5 seconds while a VBA Excel macro/script makes a graph and automatically copies that graph onto the clipboard (it's probably not really a 5 second wait, but I don't *instantly* see the new graph created that gets automatically copied to the clipboard, so I make sure to wait till I see the graph so that I know that it's really copied onto the clipboard before I go to Microsoft Word and hit "paste");
2. click on a Microsoft Word document to make it active;
3. hit "apple-V" to paste the graph into the Microsoft Word document;
4. hit "apple-S" to make sure that I don't lose the document if the computer crashes or something else goes wrong;
5. click back on the Excel document to make it active;

and now I'm back at 1, hitting "return" and waiting 5 seconds while the VBA Excel macro script does its job.

I had heard that Apple Script was good for this kind of thing, so I read some stuff about it and fiddled around a bit with the Script Editor, but I couldn't figure out how to automate this task. Does anyone know how to do this? Any advice would be much appreciated.

Thanks.

Eric
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Sep 13, 2005, 03:47 AM
 
Sounds like you need three commands:

tell app "system events" to keypress "blah" with command down.

Which simulates keystrokes,

tell app "Word" to activate.

and

delay 5

to delay.
     
Eric  (op)
Fresh-Faced Recruit
Join Date: Sep 2005
Status: Offline
Reply With Quote
Sep 13, 2005, 03:25 PM
 
Thanks! That "System Events" thing was exactly what I was looking for. I ended up with the following script, which works perfectly:

repeat 1000 times
set CR to ASCII character of 13
tell application "System Events"
tell application "Microsoft Word" to activate
keystroke "v" using command down
keystroke "s" using command down
tell application "Microsoft Excel" to activate
keystroke CR
delay 2
end tell
end repeat
     
   
Thread Tools
Forum Links
Forum 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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:54 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2