Can I map CMD+D to another tag?


#1

Hi,

English is not my first language. I like pressing Cmd + D to complete tasks. Can I map this shortcut to a different tag in my own language? (TaskPaper 3.5.1)

Thank you!

CME


#2

You can do this from the Mac Keyboard Shortcuts Preferences. So, this is not just related to TaskPaper, but something that could be done with any application. Just go into your System Preferences > Keyboard > Shortcuts. There on the left column, select “Application shortcuts”, then press the “+” button on the right and on the popup select TaskPaper as the application, write “Tag with Done” in the Menu Title and select the shortcut that you want to use instead on the box under. This should make it works.


#3

Thank you GuiB!

I don’t want to change the shortcut however, but the tag that is set when I press Cmd +D (as an example: not @done but @finished)

Regards,
CME


#4

Oh, sorry, I didn’t understand clearly… This script will do it, but you will need a way to call it from a shortcut, this could be easily done if you have an application like Alfred or LaunchBar or Keyboard Maestro or could be use with an automator service…

function TaskPaperContextScript(editor, options) {

  function setAttribute(editor, items, name, value) {
    var outline = editor.outline;
    var selection = editor.selection;	
    outline.groupUndoAndChanges(function() {
      items.forEach(function (each) {
        each.setAttribute(name, value);
      });
    });	
    editor.moveSelectionToItems(selection);
  }

  function toggleAttribute(editor, items, name, value) {
    items.forEach(function (each) {
      if (each.hasAttribute(name)) {
        value = null; // If any item has the attribute, then remove it from all.
      }
    });
    setAttribute(editor, items, name, value);
  }

  toggleAttribute(editor, editor.selection.selectedItems, 'data-finished', "");
}

Application("TaskPaper").documents[0].evaluate({
  script: TaskPaperContextScript.toString()
});


#5

If you want to run it as a service. Place this Automator workflow in “~/Library/Services/” and then you will see it in the TaskPaper services menu. Then you could add a keyboard shortcut as I told you in my first post but linking to the menu title: "Add @finished tag"Add @finished tag.workflow.zip (104.1 KB)


#6

Thank you, I’ll give it a try!

CME


#7

And if you want to keep the strikethrough over the item text like the @done tag, add this to your theme stylesheet

item[data-finished] {
  > run[content] {
    text-strikethrough: NSUnderlineStyleSingle;
    text-strikethrough-color: @text-color;
  }
}

#8

Just a remark… if you wanted to map the shortcut to something else than @finished, just change “finished” to what you want in the line:

toggleAttribute(editor, editor.selection.selectedItems, 'data-finished', "");
// Could be changed to, for example:
toggleAttribute(editor, editor.selection.selectedItems, 'data-otherTag', "");

And in the stylesheet:

item[data-otherTag] {
  > run[content] {
    text-strikethrough: NSUnderlineStyleSingle;
    text-strikethrough-color: @text-color;
  }
}

#9

@GuiB Thanks for the quick response, beat me to it!

@CME (and others)

Related to this request … I’m looking to add drag and drop support between Reminders.app reminders and TaskPaper items. I’ll want certain attributes to transfer over. For example if the reminder has a due date or priority I will encode those values in @due and @priority tags.

I guess eventually it would make sense to have some sort of localization system for all of these tags, so that they could be changed in one place and the related code and style would all update. The end result would mean some incompatibility between documents (instead of having @done everywhere for done things in text files we would have localized versions of @done … but I guess that makes sense since documents wouldn’t be that compatible anyway since they would be in a different language in the first place).

Anyway I’m going to add this as an issue to investigate further.


#10

Hi @jessegrosjean, yes this would be great and also think some kind of localization could be great

About the interface for this case (the @done, @due… and other tags), I’m also actually developing an application with an API/Scripting language that I’m thinking at letting the users define “replacement” names… What I’m thinking is to let the users create aliases.

So, on how I think this could work for TaskPaper, what about doing something in the like of the searches.taskpaper and tags.taskpaper files in the Application Support folder and to define a way in the standard TaskPaper file to define aliases.

I mean, as a user interface, I’m thinking that we could define custom alias to tags like:
@newDoneTag = @done

The alias should be put at the beginning of the file (or in an alias.taskpaper file in the Application Support to make it global) to tell TaskPaper that we want to use it for this file (or all our files by default). This way, internally, TaskPaper could switch it’s standard tags to the ones the user defined. I mean, TaskPaper will use the latest alias that is defined for a specific tag. For example, if a new alias is defined for @done, then when we do CMD+D, the alias will be put instead of @done.

And then, when TaskPaper see this alias, it act the same way as it would with the normal one. So, when we add @newDoneTag to a task, the task line will add the strikethrough formatting and the other stylesheet element that is linked to it…

For what you’re mentioning about the @due and @priority interface to the Reminder.app, with the aliases defined at the top of the file or as a global preference, this will tell TaskPaper that when we import reminder from the Reminder app, we want to convert the @due tag to what we prefer when we drop it into the TaskPaper file, so TaskPaper will use the last alias that was defined.

Also, for the localization, we could define multiple aliases in a specific files for each languages that we want to localize. Ex:
alias_fr.taskpaper :
@fait = @done @dû = @due @priorité = @priority …

With the alias method, this way we could still open files that use the default tags (@done) and the style will apply normally.

Also, this will allow the user to define their own preferred tag name for the default actions. For example, the user could prefer to use @finished instead of @done so he could define @finished = @done in is global alias.taskpaper file. Furthermore, multiple alias could be linked to the same @tag, so the standard one + the localized one + the user defined one could be used.

As for the rest of the application (the menu and things like that that are not user defined), they could be localized in a more standard way (using a file with every element translated to what they relate in the other languages)

That’s just an idea :wink: , but think this could work! :slight_smile:


#11

Or, for the UI, something could be used in the like of how we define embedded searches:
@newDoneTag @alias(@done)

However, this may be a lot of ‘@‘ … But, it may be the best and easiest way to implement for you based on your own interface