Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript copy and paste routine

Hey,

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:

http://www.youtube.com/watch?v=ktY35ldDawU

MacBook, Mac OS X (10.7.5)

Posted on Feb 7, 2013 11:56 AM

Reply
2 replies

Feb 11, 2013 5:55 PM in response to Camelot

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.

Feb 7, 2013 6:44 PM in response to DanYo23

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" usingcommand down

end tell


end tell

delay 0.2


tell application "OtherApp" to activate

tell application "System Events"

tell process "OtherApp"


keystroke "v" usingcommand down


keystrokereturn

end tell

end tell

Applescript copy and paste routine

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.