One approach:
Save clipboard body as firstLine.TXT.kmmacros (19.1 KB)
function run() {
// writeFile :: FilePath -> String -> IO ()
function writeFile(strPath, strText) {
$.NSString.alloc.initWithUTF8String(strText)
.writeToFileAtomicallyEncodingError(
strPath, true,
$.NSUTF8StringEncoding, null
);
}
var a = Application.currentApplication(),
sa = (a.includeStandardAdditions = true, a),
strClip = sa.theClipboard();
if (strClip) {
var lines = strClip.split(/[\n\r]/),
intLines = lines.length,
strHead = intLines > 1 ? lines[0] : undefined,
strTail = strHead ? lines.slice(1)
.join('\n') : undefined;
if (strTail) {
var strPath = (
sa.activate,
sa.chooseFileName({
withPrompt: 'Save As',
defaultName: strHead + '.txt'
})
).toString();
return (
writeFile(strPath, strTail),
strPath
);
}
}
}