mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-29 20:32:44 +08:00
添加runPowerShell和runAppleScript
This commit is contained in:
parent
cd152e4c88
commit
fb9b675346
@ -210,19 +210,56 @@ window.quickcommand = {
|
||||
}
|
||||
}
|
||||
|
||||
// 运行vbs脚本
|
||||
if (process.platform == 'win32') quickcommand.runVbs = function(script) {
|
||||
if (process.platform === 'win32') {
|
||||
// 运行vbs脚本
|
||||
quickcommand.runVbs = function (script) {
|
||||
return new Promise((reslove, reject) => {
|
||||
var tempfile = getQuickcommandTempFile('vbs', 'TempVBSScript')
|
||||
fs.writeFile(tempfile, iconv.encode(script, 'gbk'), err => {
|
||||
child_process.exec(`cscript.exe /nologo "${tempfile}"`, {
|
||||
encoding: "buffer"
|
||||
}, (err, stdout, stderr) => {
|
||||
if (err) reject(iconv.decode(stderr, 'gbk'))
|
||||
else reslove(iconv.decode(stdout, 'gbk'))
|
||||
var tempfile = getQuickcommandTempFile("vbs", "TempVBSScript");
|
||||
fs.writeFile(tempfile, iconv.encode(script, "gbk"), (err) => {
|
||||
child_process.exec(
|
||||
`cscript.exe /nologo "${tempfile}"`,
|
||||
{
|
||||
encoding: "buffer",
|
||||
},
|
||||
(err, stdout, stderr) => {
|
||||
if (err) reject(iconv.decode(stderr, "gbk"));
|
||||
else reslove(iconv.decode(stdout, "gbk"));
|
||||
}
|
||||
);
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
};
|
||||
// 运行powershell脚本
|
||||
quickcommand.runPowerShell = function (script) {
|
||||
return new Promise((reslove, reject) => {
|
||||
let base64str = Buffer.from(script, "utf16le").toString("base64");
|
||||
child_process.exec(
|
||||
`powershell.exe -e "${base64str}"`,
|
||||
{
|
||||
encoding: "buffer",
|
||||
},
|
||||
(err, stdout, stderr) => {
|
||||
if (err) reject(iconv.decode(stderr, "gbk"));
|
||||
else reslove(iconv.decode(stdout, "gbk"));
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
// 运行AppleScript脚本
|
||||
quickcommand.runAppleScript = function (script) {
|
||||
return new Promise((reslove, reject) => {
|
||||
child_process.execFile(
|
||||
'osascript'['-e', script],
|
||||
(err, stdout, stderr) => {
|
||||
if (err) reject(stderr);
|
||||
else reslove(stdout);
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
// python -c
|
||||
|
29
src/plugins/monaco/types/quickcommand.api.d.ts
vendored
29
src/plugins/monaco/types/quickcommand.api.d.ts
vendored
@ -313,16 +313,39 @@ interface quickcommandApi {
|
||||
): void;
|
||||
|
||||
/**
|
||||
* windows 下运行 VBS 脚本并返回运行结果
|
||||
* windows 下运行 VBS 脚本并返回运行结果 (Promise)
|
||||
*
|
||||
* ```js
|
||||
* quickcommand.runVbs(`CreateObject("SAPI.SpVoice").Speak"Hello"`)
|
||||
* quickcommand.runVbs(`CreateObject("SAPI.SpVoice").Speak"Hello, World!"`)
|
||||
* ```
|
||||
*
|
||||
* @param script VBS 代码
|
||||
* @param script VBS 脚本代码
|
||||
*/
|
||||
runVbs(script: string): Promise<string>;
|
||||
|
||||
/**
|
||||
* windows 下运行 Powershell 脚本并返回运行结果 (Promise)
|
||||
*
|
||||
* ```js
|
||||
* quickcommand.runPowerShell(`$voice = New-Object -ComObject SAPI.SPVOICE
|
||||
* $voice.Speak('Hello, World!')`)
|
||||
* ```
|
||||
*
|
||||
* @param script Powershell 脚本代码
|
||||
*/
|
||||
runPowerShell(script: string): Promise<string>;
|
||||
|
||||
/**
|
||||
* MacOS 下运行 AppleScript 脚本并返回运行结果 (Promise)
|
||||
*
|
||||
* ```js
|
||||
* quickcommand.runAppleScript(`say "Hello, World!"`)
|
||||
* ```
|
||||
*
|
||||
* @param script AppleScript 代码
|
||||
*/
|
||||
runAppleScript(script: string): Promise<string>;
|
||||
|
||||
/**
|
||||
* 在终端运行,不支持 Linux
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user