d-b
d-b

Reputation: 971

Applescript - enter strings faster

I have an Applescript that enters strings using keystroke but that is a slow solution, it is almost possible to write faster manually and my strings are long. Is there a faster way to enter text using Applescript?

Upvotes: 0

Views: 190

Answers (2)

CRGreen
CRGreen

Reputation: 3444

The efficient way to do this is to use, if possible, the most natively script-able solution on both sides of the task list. One side of course is where you get the text from; The other side is where the text goes. I'm giving fairly basic concepts here because no code examples were given. So if I have lines of text to copy, I'd put them into an app that supports AppleScript well, like TextEdit or BBEdit (two of many). Then I could script the "pasting" (this may not require actually pasting) into the 2nd part of the task list – in your case this seems to require a browser. Safari is one of if best if not the best option, partially because it supports "do JavaScript", which hooks into what the browser renders and allows you to change the contents of pages. There are various examples of how to do this on stackoverflow. With these two parts of the task list worked out, you simply automate the process by looping through the lines of text and entering the text into the appropriate page elements. The (conceptual) example I give here requires no clipboard, copying or pasting, and would be very fast, depending on whether or not you need to load a new webpage for each line of text.

This is, arguably, how it should be done, and if you know what you're doing, you can cobble something together using the amazing resource known as stackoverflow.

Upvotes: 0

wch1zpink
wch1zpink

Reputation: 3142

Here is A solution which will copy the string to the clipboard, then it will paste the string from the clipboard rather than key stroking the string. On my system, this solution was lightning fast in four different applications I tested it with.

set textToEnter to "This Is Text This Is More Text This Is More Text"
set the clipboard to textToEnter

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

Upvotes: 2

Related Questions