Workflow for Alfred: export to Markdown and create Bear note

This is a script I wrote for my own use, but maybe others would like it and care to modify it for their own purpose? It is an Alfred Workflow to take a plain text export from Dynalist (using and dashes (-) and copying to the clipboard) and then transform it into Markdown format. Then the clipboard is used to create a new note in Bear. Right now it turns first level headers into H1, second into H2 and removes the indent on level three list items. It could easily be modified to include H3 and reduce the indent on deeper level indents. If I update it later to do this I will post that here as wellā€¦

Hereā€™s a link to the workflow.

1 Like

I would use this but unfortunately I donā€™t use a mac, and those are all mac-os specific apps though

if it was in python or a webapp I would probably use it though

At the heart of it is just a very simple Perl script. Since there is some kind of wrapper from Alfred this wonā€™t work directly on other systems, but someone who knows Perl should easily be able to adapt it:

$query = "{query}";

my $find1 = "^-";
my $replace1 = "#";
$query =~ s/$find1/$replace1/gm;

my $find2 = "^    -";
my $replace2 = "\n## ";
$query =~ s/$find2/$replace2/gm;


my $find3 = "^        -";
my $replace3 = "-";
$query =~ s/$find3/$replace3/gm;

print $query;
1 Like

hm well I know absolutely nothing about perl

so basically your workflow is

  1. copy text in dynalist
  2. press a hotkey using alfred workflow file
  3. paste into bear?

Step 3 is not necessary as the script uses X-callback-URL schemes to automatically create the document, so just 2 steps.

I got excited about an alfred workflow to input to dynalist inbox, then realized I read the title wrong.

Sadly, the workflow is no longer available- could you post the workflow again, please?

Sorry about that. I donā€™t know if this still works as I havenā€™t used it lately, but here is the workflow:

Hi Kerim - I know this was a long time ago, but I just found it today - thank you so much for sharing this workflow.

I am familiar with Alfred but donā€™t know Perl. However I was able to modify your script to get the right number of header levels for my situation. I was very excited until I noticed that all of my @tags present in Dynalist had been deleted in the process.

Currently these @tags are just not present in the Bear note but everything else on the same line is preserved.

My question is do you know how to sucesfully pass ā€œ@tagsā€ from Dynalist to Bear with your script. It seems that the @ sign is a reserved character in Perl and needs to be escaped, e.g. ā€œ\@tagsā€ or ā€˜@tagsā€™.

In your script, it seems already too late by the first s/// substitute command because these values have already been stripped from $query.

It seems that this escaping, or quoting, needs to be done at the very top of your script or in a pre-processing object so that they are passed into your script and can then be passed through to Bear. Unfortunately I donā€™t have the skills and understanding to make this work.

I would appreciate any insight.

Iā€™m afraid my workflows have all changed so Iā€™m not able to test this right now, but even if I could my programming chops arenā€™t sufficient to know how to fix something like that without help. You might ask in the alfred forums?

Thanks for the quick reply. I did venture over to the Alfred Forums and have it working now.

Just in case anybody else wanders by this thread, here is what I did:

I added an Alfred ā€œReplaceā€ action between your ā€œGet Clipboardā€ and your perl script to protect the @ signs in the clipboard.

That replace is simply:
Replace "string" @ with "\@"

Then I added a s/// command at the top of your script:
$query =~ s/\"\\@\"/@/g;

This gets me back to @. It took a few goes but it turned out that I needed to escape each of the quotes and the backslash itself to get it to work.

Again thanks for getting me started with this - I expect this workflow will be very useful to me moving forward.

For reference here is the modified script. Note that the non-headers use * instead of - to give an unordered list instead of a todo list in Bear.

The final two changes were to insert tabs rather than sets of 4 spaces and remove the extra space after the * to match Bearā€™s input requirements and ensure a good export to MD if desired from Bear.

I used <tab> because I couldnā€™t find a way to insert a tab into the code block, and it adds clarity I guess!

$query = "{query}";

$query =~ s/\"\\@\"/@/g;

my $find1 = "^-";
my $replace1 = "#";
$query =~ s/$find1/$replace1/gm;

my $find2 = "^    -";
my $replace2 = "\n## ";
$query =~ s/$find2/$replace2/gm;

my $find3 = "^        -";
my $replace3 = "*";
$query =~ s/$find3/$replace3/gm;

my $find4 = "^            -";
my $replace4 = "<tab>*";
$query =~ s/$find4/$replace4/gm;

my $find5 = "^                -";
my $replace5 = "<tab><tab>*";
$query =~ s/$find5/$replace5/gm;

my $find6 = "^                    -";
my $replace6 = "<tab><tab><tab>*";
$query =~ s/$find6/$replace6/gm;

my $find7 = "^                        -";
my $replace7 = "<tab><tab><tab><tab>*";
$query =~ s/$find7/$replace7/gm;

my $find8 = "^                            -";
my $replace8 = "<tab><tab><tab><tab><tab>*";
$query =~ s/$find8/$replace8/gm;


print $query;

ļæ¼

1 Like