Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to manipulate text from Clipboard in Applescript
    text
    copied!<p>I am forced to use a piece of software that requires a lot of data entry into simple web forms, so I have designed an AppleScript to take a text file as input and then keystroke out the contents into Safari, so that tabs in the text file are used to advance to the next field in the web form. I am doing some string replacement so I can treat newlines in the text file as tabs, for readability of the text file.</p> <p>I want to streamline this by keystroking from the clipboard, which works, but the string replacement is not happening the way it should, and I am unable to determine why. My workaround at this point is to manually find/replace newlines with tabs before copying, but that's basically just as slow as saving the file and pointing the script at it.</p> <pre><code>tell application "Safari" activate end tell set sourceString to (the clipboard) as text set ASTID to AppleScript's text item delimiters set AppleScript's text item delimiters to "\n" set the lineList to every text item of sourceString set AppleScript's text item delimiters to "\t" set keystrokeString to the lineList as string set AppleScript's text item delimiters to ASTID tell application "System Events" keystroke keystrokeString as text end tell </code></pre> <p><code>\t</code> and <code>\n</code> will compile down to invisibles if you put this into AppleScript Editor. The string editing (middle) part works as advertised when I read from a file using:</p> <pre><code>set theFile to (choose file with prompt "Select a file to read:" of type {"txt"}) open for access theFile set fileContents to (read theFile) close access theFile </code></pre> <p>Any ideas why the string replacement might not be working when I get the text from the clipboard?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload