Replies: 2 comments
-
|
In order to obtain the expected linebreaks, I need to use the command Here is the full script: // Menu: Pipe to Command
// Decription: Manipulate the selected text or clipboard content using the shell
// Author: pomdtr
process.env.PATH = `${process.env.HOME}/.local/bin:/usr/local/bin/:${process.env.PATH}`;
var os = import('os'); os.EOL
function codeblock(text) {
const triple_backquote = "```";
return `${triple_backquote}shell\n${text}\n${triple_backquote}`;
}
let command = "";
const clipboardContent = await paste();
const selectedText = await kit.getSelectedText();
const tempfile = `${kit.tempdir()}/input.txt`
if (selectedText) {
await kit.writeFile(tempfile, selectedText, {flag: 'w', encoding: 'utf-8'})
} else if (clipboardContent) {
await kit.writeFile(tempfile, clipboardContent, {flag: 'w', encoding: 'utf-8'})
}
let [stdout, stderr, code] = [null, null, 0];
let panelContent = await kit.readFile(tempfile, {encoding: "utf-8"})
while (true) {
command = await arg(
{
placeholder: "Command:",
className: "px-2",
input: command,
},
md(codeblock(panelContent))
);
if (command) {
({stdout, stderr, code} = exec(`tr '\r' '\n' < ${tempfile} | ${command}`))
panelContent = code == 0 ? stdout : stderr;
} else {
panelContent = await kit.readFile(tempfile, {encoding: "utf-8"});
}
await copy(panelContent);
} |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for finding this. I dug into what was going on, here's what I found: ProblemThe internal let selectedText = await applescript(
String.raw`get the clipboard`
)The let { stdout, stderr } = exec(
`osascript -e '${formattedScript}'`,
options
)So at its core, osascript -e 'get the clipboard'So if we actually create a file and check for line endings: osascript -e 'get the clipboard' > ~/.kenv/tmp/testing-line-breaks/test.txt
file ~/.kenv/tmp/testing-line-breaks/test.txtThe result is: We don't want Quick Solution"Don't use AppleScript" 😇. I'll just replace: this: let selectedText = await applescript(
String.raw`get the clipboard`
)with this: let selectedText = await paste() // "paste" is from npm's "clipboardy"and the problem goes away. Long-term solutionLater this year, I'll be removing all the AppleScript code in favor of Rust w/ osx bindings and I'll make sure any returned strings have proper line-endings. The plan is to bring Script Kit to Windows and Rust cross-platform bindings should fit the purpose nicely. AppleScript is slow when dealing many OS-level apis (window bounds, displays, running apps, etc) and I'm excited to build much more robust OS-level tools (and keep them cross-platform) with Rust. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When saving the content of the clipboard or the current selection to a file, I get windows-style line breaks:
Is there a way to stop this behavior ?
Beta Was this translation helpful? Give feedback.
All reactions