Jump to content

DEVONthink Browser & File Action


Recommended Posts

  • 2 months later...
  • Replies 53
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Very useful - thank you for this workflow!

Just moved from years of being a devout Evernote user to DevonThink, and this workflow made that decision much easier. Cheers!

Wow, this workflow is amazing. I switched to Alfred (from Quicksilver!) back in 2015, mainly because I saw the potential for using it with DTPO. None of the Alfred/DTPO workflows available then satisf

Posted Images

On 6/23/2019 at 2:00 AM, dmccurley said:

New to Alfred. I understand what needs to be changed to access DEVONthink 3, but need some help on where the changed needs to be made.

Second this: I updated the search scope with the new metadata folder, but apparently nothing changed; I guess some of the scripts in the workflow should be updated? For example in the tell block I think know the name of the app is "DNtp"...what do you say @brunoc? 

Link to post
  • 4 months later...

@brunoc Thanks for sharing this workflow. It's fantastic - and has really improved my experience with DEVONthink! Thanks a ton!!

 

Quick Question: Is it possible - either with some modifications to the "search groups" portion of the workflow or by creating a new action - to include Global Smart Groups? I use these a ton, and would love to quickly access them in the same manner that your fantastic workflow does for normal groups.

 

Thanks again!

Link to post
On 1/24/2020 at 3:26 PM, Jasondm007 said:

@brunoc Thanks for sharing this workflow. It's fantastic - and has really improved my experience with DEVONthink! Thanks a ton!!

 

Quick Question: Is it possible - either with some modifications to the "search groups" portion of the workflow or by creating a new action - to include Global Smart Groups? I use these a ton, and would love to quickly access them in the same manner that your fantastic workflow does for normal groups.

 

Thanks again!

 

Hi @Jasondm007. Thanks for your feedback! Searching Global Smart Groups make perfect sense. I just have to figure a way to prevent this kind of choice in the "Move To..." file action. I'll give it some thought soon... 

Link to post
On 9/8/2019 at 1:00 PM, nestorito said:

Second this: I updated the search scope with the new metadata folder, but apparently nothing changed; I guess some of the scripts in the workflow should be updated? For example in the tell block I think know the name of the app is "DNtp"...what do you say @brunoc? 

 

I've updated the scripts in December – it should be working with DT3. Is it working for you guys?

Link to post
  • 3 weeks later...

Thank you @brunoc for creating this workflow, super helpful!

Has anybody tried it across sync'd databases?

 

I sync my DEVONthink database via a localsync store (and Alfred through a shared folder). 

The DEVONthink browser worked on both initially,  but stopped working on my laptop. I reinstalled with no effect.

 

Would you have recommendations on how to troubleshoot? 

Thanks!

Giovanni

 

Link to post

Hi @giovanni. It should definitely work with sync'ed databases + Alfred preferences on a shared folder. I do exactly that with Dropbox in both a laptop and an iMac.

 

Did you try forcing the cache update with dtp:refresh? Do you get any errors in debug mode (image.png.cd2e38ad629037968a16971aef007886.png) ? 

Link to post

@giovanni in addition, if you've ever duplicated the workflow, make sure it as a proper "Bundle id" (right click the workflow name on the list -> Edit details). It should be "br.com.brunoc.dtpbrowser" or anything else unique. Alfred 4 goes crazy without a warning if there's no bundle id attributed to the workflow.

Link to post

thanks @brunoc, yes I had duplicated it in the past, but left a single copy after reinstalling.

I found a difference between laptop and desktop: if I force cache refresh in debug mode, I get this, on laptop only:

 

[07:57:40.673] DEVONthink Browser[Script Filter] Queuing argument '(null)'

[07:57:40.784] DEVONthink Browser[Script Filter] Script with argv '(null)' finished

[07:57:42.174] DEVONthink Browser[Keyword] Processing complete

[07:57:42.175] DEVONthink Browser[Keyword] Passing output '' to Run Script

[07:57:42.337] STDERR: DEVONthink Browser[Run Script] ./dtp-list-groups.applescript:348:353: script error: Expected class name but found identifier. (-2741)

[07:57:42.345] DEVONthink Browser[Run Script] Processing complete

[07:57:42.346] DEVONthink Browser[Run Script] Passing output '' to Post Notification

 

does this help?

Thanks again

Giovanni

 

 

 

Link to post
  • 1 month later...

Wow, this workflow is amazing. I switched to Alfred (from Quicksilver!) back in 2015, mainly because I saw the potential for using it with DTPO. None of the Alfred/DTPO workflows available then satisfied me, I couldn't figure out how to make one myself, and I eventually gave up on linking my two favorite apps. What you've made is exactly what I've wanted all these years. Thank you!! (And thanks also for the Keyboard Maestro macro, which is a great way to keep the cache updated.)

Edited by dgbeecher
Link to post
  • 2 weeks later...

Thanks  @brunoc - I downloaded your workflow a few days ago and, after waiting for the cache to refresh, all seemed well.

 

However, a few days later I went to use the workflow again and unfortunately couldn't get it to work correctly as it had before.

 

Here is a sequence of screenshots that show how it is failing for me.  I haven't tried to debug the workflow on my end because I have no expertise but would be happy to run any tests that might help you understand what is going on.

 

I was particularly excited by the file actions and am motivated to do whatever I can on my end to make this work.

 

Thanks for developing and sharing the workflow.

 

Here is the sequence of events as I type dtp <space>.  After the space, I seem to have dropped out of your workflow.

 

 

Screen Shot 2020-04-21 at 11.45.14 AM.jpg

 

 

Screen Shot 2020-04-21 at 11.45.47 AM.jpg

 

 

Screen Shot 2020-04-21 at 11.46.06 AM.jpg

 

 

Screen Shot 2020-04-21 at 11.46.25 AM.jpg

 

 

Edited by PaulF
insert copy of images instead of URL pointers to images
Link to post

I tried again today and all seems well.  

 

I really don't know what changed.  I did see a "waiting for DEVONthink" message just before it "dropped out" of the dtp workflow before.  I saw that same message today, but this time all went well.

 

I really love the "Move to DEVONthink" file functionality combined with the group search - thanks again @brunoc!

Link to post

... not working again (no DT groups are listed as indicated in previous screenshots) and now I have enabled debug and get the following error:

 

[18:00:14.034] ERROR: DEVONthink Browser[Script Filter] JSON error: Badly formed object around character 185584. in JSON: {"items": [{"uid":"C6CB480C-35A4-4C ... ... ...[truncated]

 

This is the first and only debug message after "logging started" and is thrown as soon as dtp is typed within Alfred.

 

If I hit return to force the cache to refresh, clear the debug window and type dtp a second time I still get the same error.

 

Any help for how to proceed would be most welcome.

 

In the meantime, I am trying to find the cache file location so that I can parse the json file and see if the "badly formed" object is obvious to me.

 

I see the environment; variable ${alfred_workflow_cache} but being new to workflows am still trying to see where that variable is defined since it isn't one of the user settings.

 

Link to post

@brunoc  I have looked at my databases and I do have some groups with a quote (") in the name, and that is causing the problem.

 

I created a small test database containing a group with a quote (") in the name.  I then stepped through your script: dtp-list-groups.applescript (outside of Alfred) and captured  the jsonOutput.

 

I then looked at that data with a JSON formatter  and I get an error unless:

    1. I manually delete the extra quote (")
    2. I manually insert a backslash (\) in front of the quote (")

 

I see how an extra quote would cause problems given the reliance of the quote (") in the JSON format itself.   However, I did find that people are using backslashes to escape the quote (") in similar situations How to escape double quotes in JSON.

 

I don't know if you can encode the strings to protect the quote (") going into the jsonOutput or how this might affect the query side of your script.

 

In the meantime, I will remove the quotes (") from those group names.

 

Thanks again for providing this very useful workflow.
 

 

Link to post

@brunoc I just did a proof of concept test using my small test database that has the problematic group name

 

    1. I ran "dtp" and forced the cache to update - it failed, as usual, because of the extra quote (").

    2. I then went to the cache and edited the "broken" jsonOutput by inserting a backslash (\) in front of the extra quote (")

    3. I then reran "dtp" and this time there was no error and everything works as expected ... until the cache updates.

 

Here is the window showing the group name with the internal quote (").

 

88468495_ScreenShot2020-05-03at12_30_30PM.png.99ff5818847e9ccd087c308212c6f192.png

 

Selecting this group works as expected and the group is opened within DEVONthink correctly!

 

Link to post

@PaulF Those groups containing quote marks are the culprits! You'll have to rename them. Being a very lame AppleScript programmer myself, I was unable to find a way to protect some variables against this problem 😞 

Link to post

@brunoc I think this works:

 

The strategy is to escape the quote (") as (\") as required for JSON.

 

Quote

The following characters are reserved in JSON and must be properly escaped to be used in strings:

  • Backspace is replaced with \b
  • Form feed is replaced with \f
  • Newline is replaced with \n
  • Carriage return is replaced with \r
  • Tab is replaced with \t
  • Double quote is replaced with \"
  • Backslash is replaced with \\

 

All I did was introduce a "findAndReplaceInText" generic routine for replacing text in strings from the Mac Automation Scripting Guide which can then be used to escape the group name strings.

 

I used that routine in your "addToGroups" to replace any quotes (") within "theName" to (\").

 

The routine string parameters are actually "\"",  and  "\\\"

    To add a single quote to a string in AppleScript already requires it be specified as \"

    To specify the required output means adding two backslashes, I think the first escapes the second!

 

When I look at the JSON output, your original code using "theName" gives:

         "2019-08-19: 3" tie in west pasture"

 which causes a problem for JSON.

 

However, using the modified code with "theEscapedName" gives:

        "2019-08-19: 3\" tie in west pasture"

which is accepted by JSON and doesn't seem to affect the functioning of the rest of your code.

 

Quote

on findAndReplaceInText(theText, theSearchString, theReplacementString)

set AppleScript's text item delimiters to theSearchString

set theTextItems to every text item of theText

set AppleScript's text item delimiters to theReplacementString

set theText to theTextItems as string

set AppleScript's text item delimiters to ""

return theText

end findAndReplaceInText

 

on addToGroups(theName, theUUID, theDB)

if (my numCurrentLevelmy numLevelMin) and (my numCurrentLevelmy numLevelMax) then

set theEscapedName to findAndReplaceInText(theName, "\"", "\\\"")

set the end of my lstGroups to {theEscapedName, theUUID, theDB}

end if

end addToGroups

Link to post
8 hours ago, PaulF said:

@brunoc I think this works:

 

The strategy is to escape the quote (") as (\") as required for JSON.

 

 

All I did was introduce a "findAndReplaceInText" generic routine for replacing text in strings from the Mac Automation Scripting Guide which can then be used to escape the group name strings.

 

I used that routine in your "addToGroups" to replace any quotes (") within "theName" to (\").

 

The routine string parameters are actually "\"",  and  "\\\"

    To add a single quote to a string in AppleScript already requires it be specified as \"

    To specify the required output means adding two backslashes, I think the first escapes the second!

 

When I look at the JSON output, your original code using "theName" gives:

         "2019-08-19: 3" tie in west pasture"

 which causes a problem for JSON.

 

However, using the modified code with "theEscapedName" gives:

        "2019-08-19: 3\" tie in west pasture"

which is accepted by JSON and doesn't seem to affect the functioning of the rest of your code.

 

Same problem here! I tested on a small new database and I had no problem while adding back my work database breaks the workflow with the same error:

Quote

JSON error: Unescaped control character around character 15453. in JSON

The problem is I'm not able to finde a group in the work database that could contain quote marks, any hint on how 'correct' the problem? I don't understand where to add the rename routine...

 

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...