我希望能够在文件中选择文本并将其发送到外部终端。这可能吗?
如果没有,可以通过applescript完成吗?
答案 0 :(得分:0)
我最终使用AppleScript编写自己的extension来执行此操作。就这么简单:
function activate(context) {
const runIterm = vscode.commands.registerCommand('run-external.iterm', function() {
const editor = vscode.window.activeTextEditor;
let textToPaste;
if (editor.selection.isEmpty) {
textToPaste = editor.document.lineAt(editor.selection.active.line).text;
} else {
textToPaste = editor.document.getText(editor.selection);
}
exec(
`osascript ` +
` -e 'tell app "iTerm"' ` +
` -e 'set mysession to current session of current window' ` +
` -e 'tell mysession to write text "${textToPaste}"' ` +
` -e 'end tell'`
);
});
context.subscriptions.push(runIterm);
}
exports.activate = activate;