想要把【打开文件位置】写一个自定义脚本,给加上快捷键,有人会写脚本吗 #307
-
另外问一问zotero这些api啊函数啊有官方文档吗 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
感觉可以参考这个试着改一改 #132 |
Beta Was this translation helpful? Give feedback.
-
是的,我就是仿照这个写了脚本 const window = require("window");
let filePath;
if (item.isRegularItem()) {
targetItem = (await item.getBestAttachments()).find(
(att) =>
att.isPDFAttachment() ||
att.isSnapshotAttachment() ||
att.isEPUBAttachment()
);
if (targetItem) {
filePath = await targetItem.getFilePathAsync();
}
else{
Zotero.alert(window, "信息面板", "该条目没有附件");
}
}
else{
filePath = await item.getFilePathAsync();
}
let exePath = "D:\\OneCommander\\OneCommander.exe"
Zotero.launchFileWithApplication(filePath, exePath);
return "打开成功"; 现在的问题是,我使用的是自己安装的文件管理器 如果想改成win自带的系统资源管理器,还是有些问题 希望有大佬能看看帮忙解决 当然我觉得这个办法还是比较笨的,要自己获取文件路径 ,然后用某个exe打开,我认为zotero既然给右键菜单加了这个【打开文件位置】的选项,我想应该是有api可以直接用的,只是我对此并不熟悉,也没找到文档,就无能为力了 |
Beta Was this translation helpful? Give feedback.
-
用系统资源管理器的可用代码 const window = require("window");
let filePath;
if (item.isRegularItem()) {
targetItem = (await item.getBestAttachments()).find(
(att) =>
att.isPDFAttachment() ||
att.isSnapshotAttachment() ||
att.isEPUBAttachment()
);
if (targetItem) {
filePath = await targetItem.getFilePathAsync();
}
else{
Zotero.alert(window, "信息面板", "该条目没有附件");
}
}
else{
filePath = await item.getFilePathAsync();
}
let folderPath = filePath ? filePath.replace(/\\[^\\]+$/, ''): null;
let exePath = "C:\\Windows\\explorer.exe"
Zotero.launchFileWithApplication(folderPath, exePath);
return "打开成功"; |
Beta Was this translation helpful? Give feedback.
-
综合借助上面作者的回答,补充一段我修改的在macOS和Windows下都可以打开附件文件夹且Zotero不会报错的代码: /**
* Finder Opener
* @author Calmwave, ProudBenzene
* @reference https://github.com/windingwind/zotero-actions-tags/issues/235
* @usage Open the folder of the attachment in Finder/Default Explorer
* @link https://github.com/windingwind/zotero-actions-tags/discussions/307
* @see https://github.com/windingwind/zotero-actions-tags/discussions/307
*/
const win = require ('Zotero').getMainWindow();
targetItem = (await item.getBestAttachments()).find(
(att) =>
att.isPDFAttachment() ||
att.isSnapshotAttachment() ||
att.isEPUBAttachment()
);
if (!targetItem) {
return "[Finder Opener] No Attachments in this Item";
}
// Zotero.launchFileWithApplication(folderPath, exePath);
win.ZoteroPane.showAttachmentInFilesystem(targetItem.id);
return "[Finder Opener] 打开成功"; |
Beta Was this translation helpful? Give feedback.
ZoteroPane.showAttachmentInFilesystem(itemID)