From a32d8fba8dc30be22d838b52aa9c85b32fda0cae Mon Sep 17 00:00:00 2001 From: fofolee Date: Fri, 10 Apr 2020 12:43:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=AE=98=E6=96=B9API?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=80=89=E4=B8=AD=E7=9A=84=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=8F=8A=E8=B5=84=E6=BA=90=E7=AE=A1=E7=90=86=E5=99=A8=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- preload.js | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/preload.js b/preload.js index 49cb608..bf313bc 100644 --- a/preload.js +++ b/preload.js @@ -143,7 +143,6 @@ getSelectFile = hwnd => repeat with theItem in selectedItems set pathData to pathData & POSIX path of theItem & linefeed end repeat - set stdout to pathData ' ` exec(cmd, (err, stdout, stderr) => { @@ -181,16 +180,7 @@ pwd = hwnd => } }); } else { - var cmd = `osascript -l JavaScript -e ' - const frontmost_app_name = Application("System Events").applicationProcesses.where({ frontmost: true }).name()[0] - if (frontmost_app_name === "Finder") { - unescape(Application("Finder").insertionLocation().url()).slice(7).slice(0, -1) - } else if(frontmost_app_name === "Path Finder") { - unescape(Application("Path Finder").finderWindows[0].target.url()).slice(7).slice(0, -1) - } else { - unescape(Application("Finder").desktop.url()).slice(7).slice(0, -1) - } - '` + var cmd = `osascript -e 'tell application "Finder" to get the POSIX path of (target of front window as alias)'` exec(cmd, (err, stdout, stderr) => { if (err) reject(stderr) reslove(stdout.trim()); @@ -281,11 +271,11 @@ run = async (cmd, option, codec, terminal, callback) => { var chunks = [], err_chunks = []; child.stdout.on('data', chunk => { - chunk = iconv.decode(chunk, 'GBK') + if (isWin) chunk = iconv.decode(chunk, 'GBK') chunks.push(chunk) }) child.stderr.on('data', err_chunk => { - err_chunk = iconv.decode(err_chunk, 'GBK') + if (isWin) err_chunk = iconv.decode(err_chunk, 'GBK') err_chunks.push(err_chunk) }) child.on('close', code => {