Skip to content

Instantly share code, notes, and snippets.

@davemacdo
Created April 13, 2017 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davemacdo/acdbb7a43cccc1886c937a6468a3fca1 to your computer and use it in GitHub Desktop.
Save davemacdo/acdbb7a43cccc1886c937a6468a3fca1 to your computer and use it in GitHub Desktop.
Copy-paste columns from Numbers (or Excel) to v3 webform
// Input from clipboard formatted in two columns: | Grade | HTML comment |
// Pastes into the v3 form
function run(input, parameters) {
currentApp = Application.currentApplication();
se = Application("System Events");
currentApp.includeStandardAdditions = true;
clip = currentApp.theClipboard();
var score, comment;a
clip.indexOf("\t");
if (clip.indexOf("\t") != -1) { // Excel handler (not thoroughly tested)
str = clip.split(/[\n\t\r]+/);
dropKick(str);
//console.log(str);
} else { // Numbers handler
str = clip.split("\r");
str.shift();
str.pop();
str.pop();
dropKick(str);
//console.log(str);
}
function dropKick(bigArray){
for (i = 0; i < bigArray.length; i++){
// console.log(i);
currentApp.setTheClipboardTo(bigArray[i]); // set part to clipboard
se.keystroke("v", {using: "command down"}); // paste with keyboard emulation
delay(0.3); // futz with delay if problems
se.keyCode(48); // tab to next form element
}
currentApp.setTheClipboardTo(clip)
}
return input;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment