mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 14:34:13 +08:00
使用官方API获取选中的文件及资源管理器路径
This commit is contained in:
parent
4fab9e0da7
commit
a32d8fba8d
16
preload.js
16
preload.js
@ -143,7 +143,6 @@ getSelectFile = hwnd =>
|
|||||||
repeat with theItem in selectedItems
|
repeat with theItem in selectedItems
|
||||||
set pathData to pathData & POSIX path of theItem & linefeed
|
set pathData to pathData & POSIX path of theItem & linefeed
|
||||||
end repeat
|
end repeat
|
||||||
set stdout to pathData
|
|
||||||
'
|
'
|
||||||
`
|
`
|
||||||
exec(cmd, (err, stdout, stderr) => {
|
exec(cmd, (err, stdout, stderr) => {
|
||||||
@ -181,16 +180,7 @@ pwd = hwnd =>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var cmd = `osascript -l JavaScript -e '
|
var cmd = `osascript -e 'tell application "Finder" to get the POSIX path of (target of front window as alias)'`
|
||||||
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)
|
|
||||||
}
|
|
||||||
'`
|
|
||||||
exec(cmd, (err, stdout, stderr) => {
|
exec(cmd, (err, stdout, stderr) => {
|
||||||
if (err) reject(stderr)
|
if (err) reject(stderr)
|
||||||
reslove(stdout.trim());
|
reslove(stdout.trim());
|
||||||
@ -281,11 +271,11 @@ run = async (cmd, option, codec, terminal, callback) => {
|
|||||||
var chunks = [],
|
var chunks = [],
|
||||||
err_chunks = [];
|
err_chunks = [];
|
||||||
child.stdout.on('data', chunk => {
|
child.stdout.on('data', chunk => {
|
||||||
chunk = iconv.decode(chunk, 'GBK')
|
if (isWin) chunk = iconv.decode(chunk, 'GBK')
|
||||||
chunks.push(chunk)
|
chunks.push(chunk)
|
||||||
})
|
})
|
||||||
child.stderr.on('data', err_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)
|
err_chunks.push(err_chunk)
|
||||||
})
|
})
|
||||||
child.on('close', code => {
|
child.on('close', code => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user