Prompt from list of files does not work: path unknown

I'm assuming a .docx extension, since you missed that bit out. Doesn't matter what it is as long as there's something!

One problem: Your regex "find everything after the last backslash and replace it with itself then two underscores then itself again". So your prompt list text for the string above is actually

/Users/ronald/Documents/Dropbox/Jerry IMAC backup of important systems files/Web Site Registrations and Online Access/Web Site Registrations and Accessibility by Jerry CURRENT FILE filtered by accessibility and reliability10 Aug 2022 at 19-57.doc__Web Sites__Web Site Registrations and Accessibility by Jerry CURRENT FILE filtered by accessibility and reliability10 Aug 2022 at 19-57.doc__Web Sites

...with __Web Sites at beginning and end of the string the prompt displays. That's just a display issue though. The resulting file path is:

/Users/ronald/Documents/Dropbox/Jerry IMAC backup of important systems files/Web Site Registrations and Online Access/Web Site Registrations and Accessibility by Jerry CURRENT FILE filtered by accessibility and reliability10 Aug 2022 at 19-57.doc

...which matches your input path.

But... Dropbox. Are all the files on Dropbox also stored locally, or are they online-only? I've seen problems with other apps, eg backup software, when trying to access Dropbox's online-only "stub" files.

Because when I make a new Word doc with the following path, even longer than yours, the macro works fine:

/Users/nige_s/Dropbox (organisation removed)/Jerry IMAC backup of important systems files/Web Site Registrations and Online Access/Web Site Registrations and Accessibility by Jerry CURRENT FILE filtered by accessibility and reliability10 Aug 2022 at 19-57.docx

...so there's no issue with path length.

2 Likes

Dropbox is local.
One last question and I shall leave you in peace.
Normally, if you enter /Users/nige_s/Dropbox/test.txt__This is a test
you will only see This is a test in the list displayed when you run the macro.
If instead (like in my case), you see This is a test followed by the path (/Users/nige_s/Dropbox/test.txt), does it mean anything ?

In the unaltered macro you linked to in your OP, putting /Users/nige_s/Dropbox/test.txt__This is a test in the "SET List of YOUR current File Paths..." action will result in the pick list displaying

If you are getting anything else you need to post the macro you are actually using.

If all you want to display is the "friendly text" that you are manually entering at the end of the file path, you don't need your regex search and replace at all. Just let the "Prompt with List" action handle displaying the text after __ while returning the string before it.

2 Likes

Well, you found the problem.

After I deleted the regex, presto, everything works fine, including the long file names. I am stunned. Bravo for your idea !
Are you able to decipher the regex to know what it is doing ?

I now created 3 versions of the macro: one for web sites, one for files and one for all kinds of links to documents within apps like Bear, Scrivener and DevonThink

I just tested them, and with your idea of deleting the regex, all 3 work perfectly.

My objective now is to integrate all 3 into one macro which works with all types of links (web sites, files and links to documents within apps I use like Bear, Scrivener and DevonThink.

I plan to use the macro to store all documents and reference material that I am currently working on.

Typical web site syntax
https: //www.reddit.com/r/regex/ (I had to add a space between https: and // so the web site does not display)

Typical File Syntax
/Users/ronald/Documents/Dropbox/Calendars/September 2022.pdf

Typical App links

x-scrivener-item:///Users/ronald/Documents/Scrivener%20scriv%20files/SF%20Medical%20Manual%20SMM%20lesson%20lessons%20for%20my%20Pelz.scriv?id=A0FEAD7A-B367-423D-ACB6-A4422DE988A2

bear://x-callback-url/open-note?id=FE039A8B-1236-44DC-99DF-02874F2F0432-47699-000062E3D54F2E7B

x-devonthink-item://CCE39AB6-B459-48B6-B37D-6543FF4C185D

How and where in the macro would you suggest I create the 3 branches based on the Local__PromptList variable syntax. Should I use an if then else action ?

thanks again !

1 Like

See earlier. Pop in "Display text" actions before and after the search and replace action and you'll see what's going on (I find that easier than using the debugger, tbh).

I'd go with a "Switch/Case" action:

Switch
    variable starts with "https://"
        do web thing
    variable starts with "x-scrivener-item"
        do scrivener thing
    variable starts with "bear://"
        do bear thing
    otherwise
        do file thing
End Switch

Do check though -- I wouldn't be surprised if you only had to test for :// in the string. If present let the protocols handle app choice, it it isn't there it's a file path.

Where you do that depends on whether or not you have multi-selection and mixed lists. If you do you'll have to test for each path so it would go inside the "For Each" action. If multi-selections aren't mixed you only have to test the first then treat the rest the same.

To be honest, the test will add so little time to the processing that I'd just put it in the "For Each" action and test every path -- then you're covered for single items, multi-selections of the same protocol, and multi-selections of different types without having to think about it.

3 Likes

This is very useful, a bookmark service inside KM.

The list of creative and useful things one can do with KM are ever growing infinite.

Please do share when you have some progress, or post here what you have so far to let us iterate on that.
Thanks @ronald

2 Likes

@Nige_S @hello @tiffle @ComplexPoint

Thank you @Nige_S for suggesting a Switch action

I will post the "final" product ie the macro, hopefully today.

2 Likes

@Nige_S @hello @tiffle

Here is the macro. I tested 3 individual macros which all work fine, one for URLs opened in same tab, one for files and one to open notes in Scrivener, DevonThink and Bear

Thank you to @DanThomas for the open in same tab actions.

When I created a composite macro with all three and the switch action, it's a disaster. Only the open files work (ex: September calendar or Account).

In addition, in terms of workflow, I was wondering if instead of pick from a list in the macro, we could pick from a list in a text file. My point is that this collection of "work in progress" web sites, files and notes is constantly changing. I will than write a companion separate macro to edit that list which is much simpler than editing the list in the macro itself.

thank you

↑ Pick From List Composite Files,URL,Bear,Scrivener,DevonThink Notes UPLOADED TO KBM FORUM.kmmacros (1.8 MB)

I was thinking along similar lines -- a text file would be much easier to edit!

So here's a text file using your example bookmarks plus a macro that reads from it to produce your prompt. You can multi-select, for those times you want to eg open a web site and the document you take notes in as one operation.

I haven't done much with "deep links" (or whatever they're called), but IIRC as long as the protocol is properly registered with the OS you just use "Open URL" with the link and everything's automatic -- in which case we only need two "results":

  1. If the "bookmark" contains :// it's an URL, otherwise...
  2. ...it's a file path

But that may not be the case or you may want to do something different depending on the protocol, so I've included an example "exception" for Scrivener. Add more exceptions at the start of the "Switch/Case" action so the process is:

  1. Check for exceptions and deal with them appropriately
  2. Check if it's an URL, if so "Open URL"
  3. Otherwise it's a file path, open with default app

The trick is that "Switch/Case" exits after the first match so, in our example, the Scrivener link be matched by the first "Switch", processed in the first "Case", and would never reach steps 2 and 3.

Since the "Otherwise" "Switch" catches everything that hasn't been previously matched it's a good idea to error check it in case it isn't actually a file path. Easiest way is to just "Try" and open it and "Catch" any error if it fails.

Hopefully this'll give you something to further build on:

Pick from Bookmarks List.kmmacros (6.0 KB)

Macro Image

And the contents of the "bookmarks file" -- for the example it would be called My KM Bookmarks.txt on your Desktop:

Bookmarks file text
# Comment lines start with a #, like this one, and will be ignored
# As will empty lines

# Put one, complete, URL or file path per line
# Easiest way to add a file path is to Control- or right-click
# it in the Finder, then hold down the Option key and select 
# "Copy <filename> as Path" then paste it in here

# If you want to show "friendly names" in your list, append two underscores then
# the text you want to the path, eg
# 		http://www.example.com/__Open Example Website

~/Documents/Dropbox/current accounts.numbers__Accounts
~/Downloads/September 2022.pdf__September Calendar
https://edition.cnn.com/__CNN
https://www.wsj.com/__WSJ
bear://x-callback-url/open-note?id=EF4798CC-F9B9-4465-B549-8A3AEB427D0F-38507-000059EAB0ED314B__Test Bear Note
x-scrivener-item:///Users/ronald/Documents/Scrivener%20scriv%20files/Scriv?id=A4ECCA13-11FB-4C92-A93C-68BFEBA48ABD__Test Scrivener Note
x-devonthink-item://01925031-A366-4EC5-8E0E-A8AF5BD5DF1C__DevonThink Note
2 Likes

Great macro ! !

I made a few corrections to handle Scrivener, multiple choices, etc and all seems to work perfectly.

Current version
↑ Pick from Bookmarks Nig List 12 Aug 2022 at 13-46 UPLOAD VERSION 2 Fri, 2022 Aug 12 1-56.kmmacros (1.8 MB)

Let's say that I have a DevonThink document with the path
x-devonthink-item://BD0EFFB8-6887-45F5-ACC0-A8362E5F99D1?page=0

I can enter the following into my Bookmarks txt file
x-devonthink-item://BD0EFFB8-6887-45F5-ACC0-A8362E5F99D1?page=0__September 2022 p0 of 1

In many circumstances, it's even easier to simply copy the markdown link of a document, file, web site or note (1)

example

September 2022 p0 of 1

Do you think that it's possible to be able to enter either path__title or simply the markdown link in the bookmarks list

The difference between the 2 methods are

currently path__title

I would like to add (that the macro recognizes) the ability to enter
[title] ( path) (I had to add spaces to avoid it being converted automatically to a link)

thanks you again

(1) see macro created by the brilliant @ComplexPoint

To get from a Markdown link like

[September 2022 p0 of 1](x-devonthink-item://BD0EFFB8-6887-45F5-ACC0-A8362E5F99D1?page=0)

...to the "Prompt with list" format of

x-devonthink-item://BD0EFFB8-6887-45F5-ACC0-A8362E5F99D1?page=0__September 2022 p0 of 1

...is just a regex -- the only complication is that there's "special" characters that need to be escaped. See this action:

Search and Replace.kmactions (638 Bytes)

Image of action

Question about your changes -- do actually need to explicitly use DEVONthink 3 to open x-devonthink-item:// links, etc? Doesn't the fact that DEVONthink 3 is the registered handler for those links mean you can just use "Default Application", and that'll be DEVONthink?

Just thinking ahead for when those apps get upgraded, so you don't have to go and change them all!

2 Likes

everything works perfectly when I add your new regex.

The only way I could get the macro to work is by having a switch case for each file type. Otherwise, the macro works erratically, sometimes wanting to open the Scrivener link in Chrome.

thanks a million. So much accomplished today thanks to you !

1 Like

@hello @Nige_S

a little separate macro that I find useful

When I find a link I want to add to the file, I just copy it and trigger this one action macro

1 Like

Pop a dialog in there too, asking for the "friendly name" to use, then concat that with the contents of the clipboard with %SystemClipboard%__%Variable%Local_friendlyName%, and you've a one-stop shop!

thank you. Very useful.

I will create another version of the macro I wrote to append clipboard when I use the markdown link.

Note that I had to make a few adjustment

  • add carriage return before appending text
  • reload file from disk (with BBEdit)

So all is great thanks to you

There is one little residual glitch in the main bookmarks macro: when multiple windows are open in chrome and I open a pre existing tab, the macro does navigate to the already open tab in question but it does not put that window at the front, I have to check all windows to see in which one the tab is open.

1 Like

Great idea, automating KM to automate KM @ronald !

1 Like

thank you !

Are you adding the Return as a separate action? If so, just roll it in with the other "Append Text" action by including the token there: %SystemClipboard%__%Variable%Local_friendlyName%%Return%.

You should only need to reload the file in BBEdit to update BBEdit's take on its current contents if the file is open in BBEdit when you make the "background" changes. If it's not open you're needlessly opening it (and possibly needlessly launching BBEdit, though I have it running all the time), so you may want to add an "if any BBEdit window title is..." action in there.

But BBEdit usually does this as necessary -- check you've got "Automatically refresh documents..." turned on in Preferences->Application.

great suggestions. thanks very much

I am absolutely delighted with the macro and it's impact on my workflow.
I am writing a "clean-up" macro for the bookmarks file (only one blank line between lines, etc) which basically consists of a series of regex.
What would be the best way to regex a file ? Does the file have to be open (in my case with BBEdit) ?
thank you

1 Like