Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mac下快捷键的设置 #34

Closed
fredericky123 opened this issue Mar 19, 2024 · 9 comments
Closed

mac下快捷键的设置 #34

fredericky123 opened this issue Mar 19, 2024 · 9 comments

Comments

@fredericky123
Copy link

我想设置mac下 cmd+shift+delete为仅删除所有附件的快捷键,runjavascript应该怎么写呢

@redleafnew
Copy link
Owner

redleafnew commented Mar 19, 2024

// 删除条目和附件
static async delItemAtt() {
var zoteroPane = Zotero.getActiveZoteroPane();
var items = zoteroPane.getSelectedItems();
// var iaInfo = items.length > 1 ? 'delete-item-and-attachment-mul' : 'delete-item-and-attachment-sig';
// var truthBeTold = ztoolkit.getGlobal("confirm")(getString(iaInfo))
var truthBeTold = ztoolkit.getGlobal("confirm")(getString("delete-item-and-attachment", { args: { count: items.length } }));
if (truthBeTold) {
HelperExampleFactory.delAttDo(items); // 调用仅删除附件的函数
for (let item of items) {
if (item && !item.isNote()) {
item.deleted = true;
await item.saveTx();
}
}
BasicExampleFactory.delItemAttSucess(items); // 附件条目删除成功提示;
}
}

是源代码,你可以再找相应的具体执行的函数,结合 Zotero Action & Tags插件设置快捷键。

@fredericky123
Copy link
Author

感谢,不过我没明白找对应具体的执行函数是怎么找?

我将以下代码设置为script,然后结合action&tags设置快捷键,会报错"unexpected token async"

`// 仅删除附件
static async delAtt() {
var zoteroPane = Zotero.getActiveZoteroPane();

var items = zoteroPane.getSelectedItems();
// var daoInfo = items.length > 1 ? 'delete-attachment-only-mul' : 'delete-attachment-only-sig';
// var truthBeTold = ztoolkit.getGlobal("confirm")(getString(daoInfo));
var truthBeTold = ztoolkit.getGlobal("confirm")(getString("delete-attachment-only", { args: { count: items.length } }));

if (truthBeTold) {
  HelperExampleFactory.delAttDo(items); // 调用仅删除附件的函数
  BasicExampleFactory.delAttSucess(); // 附件删除成功提示;
}

}

// 仅删除附件执行的函数
static async delAttDo(items: Zotero.Item[]) {

for (let item of items) {
  if (item && !item.isNote()) { //2 if
    if (item.isRegularItem()) { // Regular Item 一般条目//3 if
      let attachmentIDs = item.getAttachments();
      for (let id of attachmentIDs) { //4 for
        let attachment = Zotero.Items.get(id);
        let ifLinks = (attachment.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE); // 检测是否为链接模式
        var file = await attachment.getFilePathAsync();
        if (file && ifLinks) { // 如果文件存在(文件可能已经被删除)且为链接模式删除文件
          try {
            // await OS.File.remove(file); // 尝试删除文件
            await Zotero.File.removeIfExists(file);
            //await trash.remove(file);
          } catch (error) { // 弹出错误
            alert(getString("file-is-open"));
            return; // 弹出错误后终止执行
          }
        }
        // if (attachment.attachmentContentType == 'text/html' ) { // 可以筛选删除的附件类型
        attachment.deleted = true; // 删除附件(快照)
        await attachment.saveTx();
        // }

      } //4 for
    } // 3 if
    if (item.isAttachment()) { //附件条目 5 if
      var ifLinksAtt = (item.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE); //检测是否为链接模式
      var file = await item.getFilePathAsync();
      if (file && ifLinksAtt) { // 如果文件存在(文件可能已经被删除)且为链接模式删除文件
        try {
          // await OS.File.remove(file); // 尝试删除文件
          await Zotero.File.removeIfExists(file);
        } catch (error) { // 弹出错误
          alert(getString("file-is-open"));
          return; // 弹出错误后终止执行
        }
      }
      item.deleted = true;
      await item.saveTx();
    }//5if
  } //2 if

}

}`

@redleafnew
Copy link
Owner

redleafnew commented Mar 19, 2024

@redleafnew
Copy link
Owner

有些用了工具箱的函数,可能需要改造。

@fredericky123
Copy link
Author

我估计是看不懂,不太会改造了😭

@fredericky123
Copy link
Author

image 或者这里我想把alt都修改为ctrl,应该到哪里修改呢,这样在mac下估计就能运行了 image

@fredericky123
Copy link
Author

或者,现在是不是可以结合action &tags测试出修饰键是什么,如果可以通过run javascript测试出来的话,我帮助测试一下
image

@fredericky123
Copy link
Author

image

if (data.keyboard === control,${key_del_att}) {
HelperExampleFactory.delAtt();
console.log("control+" + key_del_att + " pressed");
}
询问gpt后的一些结果

@redleafnew
Copy link
Owner

https://github.com/redleafnew/delitemwithatt/releases/tag/0.1.05 老的版本你找找,看看,

@redleafnew redleafnew closed this as not planned Won't fix, can't repro, duplicate, stale Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants