Created
April 13, 2017 14:18
-
-
Save davemacdo/acdbb7a43cccc1886c937a6468a3fca1 to your computer and use it in GitHub Desktop.
Copy-paste columns from Numbers (or Excel) to v3 webform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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