uTools介绍
官网介绍如下:
uTools = your tools(你的工具集)
uTools 是一个极简、插件化的现代桌面软件,通过自由选配丰富的插件,打造得心应手的工具集合。
通过快捷键(默认 alt + space )就可以快速呼出这个搜索框。你可以往输入框内粘贴文本、图片、截图、文件、文件夹等等,能够处理此内容的插件也早已准备就绪,统一的设计风格和操作方式,助你高效的得到结果。
官网地址:https://u.tools/
uTools插件开发
uTools支持使用javascript开发插件,本身是基于electron开发,使用nodejs和web页面组合实现桌面应用的效果
开发文档地址:https://u.tools/docs/developer/welcome.html#plugin-json
新建插件项目
插件需要文件
plugin.jsonlogo.png-
index.html(如果插件需要用UI界面就需要) -
preload.js(如果需要访问nodejs等需要此文件中转)
编写plugin.json
最近在Windows10系统上管理文件发现,Windows10系统竟然没有选中部分文件或者文件夹然后创建一个新文件夹并把选中文件移动进去这个功能,似乎只能新建文件夹,然后再手动移动进去。
正好学习下uTools插件开发,自己写一个插件来实现这个小功能。
plugin.json编写
{
"main": "index.html",
"logo": "logo.png",
"preload": "preload.js",
"features": [
{
"code": "新建文件夹",
"explain": "选中文件或文件夹并自动移动或复制到一个新建文件夹中,也可以指定已经存在的文件夹",
"cmds": [
"新建文件夹",
"New Folder",
"新建目录",
"New Directory",
{
"type": "files",
"label": "新建文件夹",
"fileType": "file, directory",
"minLength": 1
}
]
}
]
}
features下面就是配置功能的,目前就一个新建文件夹功能。
下面的cmds比较重要,用于在uTools中输入部分命令来调用插件。
有这段可以通过uTools的超级面板触发,选中文件或者文件夹之后使用配置的快捷键(我配置的是鼠标中键)触发:
{
"type": "files",
"label": "新建文件夹",
"fileType": "file, directory",
"minLength": 1
}

编写preload.js
preload.js可以使用electron的部分功能,不过uTools似乎屏蔽了不少API,但是nodejs的基本API都是支持的,这个preload.js是electron环境支持的,通过这个preload.js暴露一些nodejs相关的操作,可以在web页面上访问nodejs功能,只有这样才能访问本地的文件等。
const fs = require('fs');
const path = require('path');
window.moveOrCopyFile = function (files, dir, copy) {
// 如果不是绝对路径,根据文件转换成绝对路径
dir = dir.trim();
if (!path.isAbsolute(dir)) {
dir = path.join(path.resolve(files[0].path, '..'), dir);
}
files.forEach(file => {
if (file.isDirectory) {
const subFileNames = fs.readdirSync(file.path);
const subFiles = subFileNames.map(subFileName => {
const subPath = path.join(file.path, subFileName);
const stat = fs.statSync(subPath);
return {
name: subFileName,
path: subPath,
isDirectory: stat.isDirectory(),
isFile: stat.isFile()
}
})
this.moveOrCopyFile(subFiles, path.join(dir, file.name), copy);
} else {
if (copy) {
this.customCopyFile(file.path, path.join(dir, file.name));
} else {
this.customMoveFile(file.path, path.join(dir, file.name));
}
}
});
}
window.customMoveFile = function (fromPath, toPath) {
fs.mkdirSync(path.resolve(toPath, '..'), { recursive: true });
try {
fs.renameSync(fromPath, toPath);
} catch (e) {
utools.showNotification('不支持跨盘移动文件,请使用复制方式');
throw e;
}
}
window.customCopyFile = function (fromPath, toPath) {
fs.mkdirSync(path.resolve(toPath, '..'), { recursive: true });
fs.copyFileSync(fromPath, toPath);
}
window.checkDragFile = function (file) {
const stat = fs.statSync(file.path);
file.isDirectory = stat.isDirectory();
file.isFile = stat.isFile();
}
编写页面和业务逻辑
Web界面使用vuejs3和bootstrap的样式开发。
完整代码GitHub地址:https://github.com/fugary/utools-file-to-folder
开发完成后需要在uTools中测试。
uTools中插件使用
先安装uTools的开发者工具,也是uTools的一个插件,后面开发、测试、打包、发布等都需要用到它。
新建插件
安装【uTools的开发者工具】后就可以新建插件了。

新建好插件,可以选择本地开发的工程目录下的plugin.json,这样就关联上了。

本地测试建议勾上【隐藏后台是完全退出】,比较方便修改后隐藏界面自动就有效果了,不用重新运行。
点击【开启运行】后就相当于安装好插件了。
运行效果
开启运行后,可以看到实际的效果了,我本地配置了鼠标中键触发超级面板。

在Windows资源管理器中,选中部分文件,用鼠标中键触发超级面板,选【新建文件夹】,弹出界面,输入文件夹名字,点移动到新文件夹(或者是复制到新文件夹),功能完成。

打包插件
在uTools开发者工具页面,点击打包就可以打包成UPX文件。

发布插件
在uTools开发者工具下,点击发布,需要填写一些审核信息,还需要一些截图。

点击提交审核,等待审核就可以了。

开发完成。
插件下载安装
如果已经审核通过,可以在uTools插件应用市场中搜索插件并安装。

如果审核比较慢,也可以从GitHub上下载使用:
GitHub下载地址:https://github.com/fugary/utools-file-to-folder/releases
下载最新的UPX文件
下载后拖到uTools软件中

手动安装会提示一些安全问题。