2 Replies Latest reply: Feb 11, 2013 5:55 PM by DanYo23
DanYo23 Level 1 (0 points)


I'm a total noob at applescript, but I've been trying to find a way to make code that will copy a line from text edit, paste it into a different application, hit "enter", and then copy the next line in textedit and continue to do so on a loop. Anyone know how to do this? I found a tutorial for a very similar process, but it's for Windows Macro Express. I want the script to do the exact same thing, but hit "enter" after pasting each line.

Anyone know how to do this?

Thanks so much!


The tutorial to which I reffered:


MacBook, Mac OS X (10.7.5)
  • Camelot Level 8 (46,650 points)

    Are you really sure that's what you want to do?

    It's possible, but really, really clunky. Having a script (or macro program) emulate user actions is about the poorest approach... granted, sometimes it's the only approach, but that doesn't mean that you shouldn't conisder alternatives.


    For example, AppleScript is geared much more towards driving applications directly - i.e. telling them to manipulate data directly - rather than indirectly (e.g. click here, type this, hope for the best). Usually it's better to tell AppleScript to get the selection in any given application, then insert that text at some point somewhere else (rather than using copy/paste).


    That said, if that's what you really want:


    tell application "TextEdit" to activate

    tell application "System Events"

              tell process "TextEdit"

      keystroke "c" using command down

              end tell


    end tell

    delay 0.2


    tell application "OtherApp" to activate

    tell application "System Events"

              tell process "OtherApp"

      keystroke "v" using command down

      keystroke return

              end tell

    end tell

  • DanYo23 Level 1 (0 points)

    This helped a lot. I used the code as a base to copy and paste, and then to grab the next line in a text document and paste it in. Is there some more efficient way of doing this? I am pasting into an app that acts as a keyboard for my phone, so there isn't really a way to communicate directly with the phone.

    Is there a way to have the copy and paste routine go on in the background, so that I could use my computer for something else as it repeats continuously? Currenty, the different windows need to activate for the routine to work.

    Thank you so much, I just needed a base for the code and that enabled me to tweak it accordingly.