Hi, fellow automators!
I’m having problems using the iOS clipboard (Pasteboard) in Scriptable.
I have a JavaScript that performs FIND and REPLACE on the specified text using a series of lists of regular expressions. Here’s a link to a .txt file of the script: http://share.llmmd.me/SnacDv
I know it’s long, but the first 1636 lines are nothing but regular expressions. The meat of the script is in the 15 lines that start at line 1638. I have pasted those 15 lines of code below.
Although the script runs perfectly on the Online JavaScript Editor https://js.do, it doesn’t run in Scriptable.
HERE ARE MY PROBLEMS:
(1) I think there’s something wrong with how I have the HTML headers, because Scriptable returns the error message SyntaxError: Unexpected token ‘<’
(2) In the example script I have defined the variable textInput as a specific string, but what I need is for textInput to be whatever text string is in the iOS clipboard (pasteboard).
(3) In the example script I have output the variable textOutput using the document.write function, but what I need is for textOutput to be pasted to the pasteboard as a string for subsequent use in a Siri Shortcut.
I have read the Scriptable documentation on the Pasteboard, but I can’t seem to get the syntax correct. I’m a scripting noob, so I really appreciate the help any of you can give me.
Thanks to the Automators community!
Lee
var textInput = "Onset reported as yesterday. Severity reported as severe yesterday. Severity reported as moderate today. Location is left knee. Hypertension is good. Diabetes is fair. GERD is good. Depression is good.";
function findAndReplace(myString, ...lists) {
var list = null;
for (var j = 0; j < lists.length; j++) {
list = lists[j];
for (var i = 0; i < list.length; i++) {
myString = myString.replace(list[i].pattern, list[i].replacement);
}
}
return myString;
}
var textOutput = (findAndReplace(textInput, list1, list2, list3, list4, list5));
document.write(textOutput);