9 Replies Latest reply: Feb 8, 2013 7:42 AM by leroydouglas
Karl Thomas Hove Level 1 Level 1 (5 points)

I am looking for an easy solution to copy text from a web page (always in the same location) into to Word and print.

 

A repetative task that I'd like to run by single keystroke.

 

Go to a field on a webpage, select the text, copy, change application to Word, select text in a specific location, paste and print.

 

This all works fine - I need elp with setting mouseLocation and double clicking to copy

 

 

tell application "Google Chrome"

  activate 

          tell application "System Events" to keystroke "c" using command down

end tell

tell application "Microsoft Word"

  activate

          tell application "System Events" to keystroke "v" using command down

          tell application "System Events" to keystroke "p" using command down

end tell


iMac, OS X Mountain Lion (10.8.2), Office (home)
  • 1. Re: AppleScript
    Karl Thomas Hove Level 1 Level 1 (5 points)

    I thought you gurus would be all over this, do anyone know applescript?

  • 2. Re: AppleScript
    davidsignal Level 3 Level 3 (525 points)

    It would work far better to grab the text based on its elementID rather than your mouse location.

  • 3. Re: AppleScript
    Karl Thomas Hove Level 1 Level 1 (5 points)

    I need to go to a location on a browser page select the text (customer name)

    and copy

    go to word and select xxx (where the customer name is to go in this standard letter)

    and paste the contents

     

    any help would be greatly appreciated

  • 4. Re: AppleScript
    davidsignal Level 3 Level 3 (525 points)

    get UI Browser.

    Use that to get the HTML element IDs for the text areas you want.

    Then do something like:

    tell application "System Events" to tell process "Google Chrome"

         set customerName to the value of text field 4 of group 1 of window 1 

    end tell

    tell application "System Events" to tell "Microsoft Word"

         activate

         keystroke customerName

    end tell

     

     

    you could also do it without using keystrokes by getting the elementID of the document text area in Word and then setting the value of that element to customerName.

  • 5. Re: AppleScript
    Karl Thomas Hove Level 1 Level 1 (5 points)

    in google chrome I inspected the element it is

    id="customer-name-first"

     

     

    I have no idea how to select the xxx in my word document

     

    Dear xxx

    Welcome to Sea Breeze.


    could you help me write those 2 please and insert them in here, happy to donate for your trouble

     

    tell application "Google Chrome"

      activate 

              tell application "System Events" to keystroke "c" using command down

    end tell

    tell application "Microsoft Word"

      activate

              tell application "System Events" to keystroke "v" using command down

              tell application "System Events" to keystroke "p" using command down

    end tell

  • 6. Re: AppleScript
    Karl Thomas Hove Level 1 Level 1 (5 points)

    tell application "Google Chrome" Get id="customer-name-first"

  • 7. Re: AppleScript
    davidsignal Level 3 Level 3 (525 points)

    I am at work, so I can't really test anything out at the moment....  maybe someone else on the forums will have better input.

     

    Microsoft Word (which I don't use) incorporates its own Applescript dictionary with relevant commands.  You could read the dictionary in your applescript editor.  There are also various examples of applescripts to replace text that you could search on google.

  • 8. Re: AppleScript
    Karl Thomas Hove Level 1 Level 1 (5 points)

    OK no problem, thanks for your help.

  • 9. Re: AppleScript
    leroydouglas Level 6 Level 6 (13,840 points)

    Karl Thomas Hove wrote:

     

    I thought you gurus would be all over this, do anyone know applescript?

    There is a AppleScript specific discussion forum:

     

    https://discussions.apple.com/community/mac_os/mac_os_x_technologies#/?tagSet=10 44