mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-07 21:46:12 +08:00
更改获取资源管理器路径、选中文本、选中文件的方法
This commit is contained in:
parent
63e0766389
commit
7403c55d4d
22
README.md
22
README.md
@ -1,4 +1,4 @@
|
||||
# 快捷命令 V1.1.0
|
||||
# 快捷命令 V1.1.1
|
||||
|
||||
## 简介
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
- 新增`发送系统通知`的输出模式 By [imxiny](https://github.com/imxiny)
|
||||
- 修复 php 无法输入 <? 问题,修复MacOS环境变量问题,修复脚本不能带参数问题 By [dofy](https://github.com/dofy)
|
||||
- 使用官方API来获取浏览器的URL
|
||||
- 更改获取资源管理器路径、选中文本、选中文件的方法,获取管理器路径弃用模拟按键的方式,解决污染用户剪贴板问题
|
||||
- 之前当输出模式为纯文本或HTML时,输出时会先隐藏窗口再弹出窗口,给人一种窗口闪动的错觉,影响用户体验,现在不会再闪动了,同时碍于一些原因,添加了一个限制,即当输出模式为纯文本或HTML时,无法使用`pwd`、`SelectText`、`SelectFile`三个特殊变量
|
||||
- 修复中文乱码问题(貌似)
|
||||
|
||||
@ -112,27 +113,14 @@ PS:关于环境变量问题,有些脚本执行错误问题,由于一直未
|
||||
|
||||
`切换百度/谷歌搜索` 在百度或者谷歌的搜索页面切换至另一个搜索引擎进行搜索 (python/双平台)
|
||||
|
||||
## 下载
|
||||
## 安装方法
|
||||
|
||||
[百度网盘](https://pan.baidu.com/s/1kEEQcQ1p3Rjli2sTtmCcTg) 提取码: `rbek`
|
||||
插件中心进行安装
|
||||
|
||||
[项目地址](https://github.com/fofolee/uTools-QuickerCommand)
|
||||
|
||||
[插件发布页](https://yuanliao.info/d/424)
|
||||
|
||||
## 安装方法
|
||||
|
||||
将`upx`文件拖入`uTools`输入框中安装即可
|
||||
|
||||
## 关键字
|
||||
|
||||
`快捷命令` `QuickCommand`
|
||||
|
||||
## 鸣谢
|
||||
|
||||
鸣谢`uTools`团队,插件中使用的`robotJS`使用的是`剪贴板`插件中的`robotJS`,省去了自行编译的麻烦,在此感谢!
|
||||
|
||||
## 另:两个小需求
|
||||
|
||||
希望插件的`Features`能够支持以`base64`作为图标,好实现多设备的图标同步,目前的实现方案有点麻烦~
|
||||
另外可以根据使用的操作系统动态启用或禁用某些`Feature`,即给`Feature`添加类似`platform`的功能
|
||||
`快捷命令` `QuickCommand`
|
@ -75,7 +75,7 @@ function runCmd(cmd, option, codec, output) {
|
||||
break;
|
||||
case "notice":
|
||||
// 发送系统通知
|
||||
utools.showNotification(stdout, null, true);q1c
|
||||
utools.showNotification(stdout, null, true);
|
||||
break;
|
||||
case "ignore":
|
||||
default:
|
||||
|
BIN
bin/GetForegroundWindow.exe
Normal file
BIN
bin/GetForegroundWindow.exe
Normal file
Binary file not shown.
75
preload.js
75
preload.js
@ -4,9 +4,8 @@ const { spawn, exec } = require("child_process")
|
||||
const iconv = require('iconv-lite')
|
||||
const { clipboard } = require('electron')
|
||||
const robot = utools.robot
|
||||
const jschardet = require("jschardet")
|
||||
// const jschardet = require("jschardet")
|
||||
|
||||
//-------checkUpdate------
|
||||
const path = require("path")
|
||||
const { dialog, BrowserWindow, nativeImage } = require('electron').remote
|
||||
const { shell } = require('electron');
|
||||
@ -80,12 +79,55 @@ paste = () => {
|
||||
robot.keyTap('v', ctlKey);
|
||||
}
|
||||
|
||||
// 保存剪贴板
|
||||
storeClip = () => {
|
||||
var formats = clipboard.availableFormats("clipboard");
|
||||
if (formats.includes("text/plain")) {
|
||||
return ['text', clipboard.readText()]
|
||||
}
|
||||
if (formats.includes("image/png") || formats.includes("image/jpeg")) {
|
||||
return ['image', clipboard.readImage()]
|
||||
}
|
||||
var file;
|
||||
if (isWin) {
|
||||
file = clipboard.readBuffer('FileNameW').toString('ucs2').replace(/\\/g, '/');
|
||||
file = file.replace(new RegExp(String.fromCharCode(0), 'g'), '');
|
||||
} else {
|
||||
file = clipboard.read('public.file-url').replace('file://', '');
|
||||
}
|
||||
if (file) {
|
||||
return ['file', file]
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
// 恢复剪贴板
|
||||
restoreClip = historyData => {
|
||||
if (historyData[0] == 'text') {
|
||||
clipboard.writeText(historyData[1]);
|
||||
return
|
||||
}
|
||||
if (historyData[0] == 'image') {
|
||||
clipboard.writeImage(historyData[1]);
|
||||
return
|
||||
}
|
||||
if (historyData[0] == 'file') {
|
||||
utools.copyFile(historyData[1])
|
||||
return
|
||||
}
|
||||
clipboard.writeText('')
|
||||
}
|
||||
|
||||
getSelectText = () => {
|
||||
var historyData = storeClip()
|
||||
copy();
|
||||
return clipboard.readText()
|
||||
var selectText = clipboard.readText()
|
||||
restoreClip(historyData)
|
||||
return selectText
|
||||
}
|
||||
|
||||
getSelectFile = () => {
|
||||
var historyData = storeClip()
|
||||
copy();
|
||||
var filePath;
|
||||
if (isWin) {
|
||||
@ -94,21 +136,32 @@ getSelectFile = () => {
|
||||
} else {
|
||||
filePath = clipboard.read('public.file-url').replace('file://', '');
|
||||
}
|
||||
restoreClip(historyData)
|
||||
return filePath;
|
||||
}
|
||||
|
||||
getAddr = () => {
|
||||
robot.keyTap('d', 'alt');
|
||||
robot.setKeyboardDelay(10);
|
||||
return getSelectText().replace(/\\/g, '/');
|
||||
}
|
||||
// 获取前台窗口句柄
|
||||
GetForegroundWindow = callback =>
|
||||
exec(`"${path.join(__dirname, 'bin', 'GetForegroundWindow.exe')}"`, (error, stdout, stderr) => {
|
||||
callback(stdout);
|
||||
});
|
||||
|
||||
|
||||
|
||||
pwd = () =>
|
||||
new Promise((reslove, reject) => {
|
||||
if (isWin) {
|
||||
var addr = getAddr();
|
||||
if (!exists(addr)) addr = `${os.homedir().replace(/\\/g, '/')}/Desktop`;
|
||||
reslove(addr);
|
||||
GetForegroundWindow(hwnd => {
|
||||
var cmd = `powershell.exe -NoProfile "((New-Object -COM 'Shell.Application').Windows() | Where-Object { $_.HWND -eq (${hwnd}) } | Select-Object -Expand LocationURL).replace('file:///','')"`;
|
||||
exec(cmd, { encoding: "buffer" }, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
console.log(stderr);
|
||||
reslove(`${os.homedir().replace(/\\/g, '/')}/Desktop`)
|
||||
} else {
|
||||
reslove(decodeURIComponent(iconv.decode(stdout, 'GBK').trim()));
|
||||
}
|
||||
});
|
||||
})
|
||||
} else {
|
||||
var cmd = `osascript -l JavaScript -e '
|
||||
const frontmost_app_name = Application("System Events").applicationProcesses.where({ frontmost: true }).name()[0]
|
||||
|
Loading…
x
Reference in New Issue
Block a user