Questions about opening files on Alfred

As shown in the figure, after entering the link in Alfred, is there a way to open it directly with PDF expert? Instead of opening in DT and then choose to open in PDF Expert.

Thank you very much for your answer :pray:

No, there’s not. That’s not how URL schemes work.
The URL scheme belongs to DEVONthink and only activates it.

I don’t run Alfred, but it would likely be possible to create a Powerpack workflow get record with uuid, get the path of the item, and pass that to PDF Expert to open.

I will try it. Thanks for your advice. :grinning:

You’re welcome :wink:

This script uses the default app to open the record

-- Open record with default app

set theReferenceURL to "x-devonthink-item://4D3C5C22-DF6C-4264-A279-A0B7386A2822" -- replace this with e.g. Alfred's input

tell application id "DNtp"
	try
		set theRecord to (get record with uuid theReferenceURL)
		if theRecord = missing value then error "No record"
		set thePath to path of theRecord
		if thePath = "" or (POSIX file thePath as string) ends with ":" then error "No file"
		tell application "Finder"
			open file (POSIX file thePath as alias)
		end tell
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

Oh! Thank you so much for your reply! But I don’t know anything about how to use computer scripts. If you have time, can you give me an overview of how the script should be used?

Thanks again! :heart: :heart:

Perhaps you can provide very effective guidance, if you wish? :laughing: @BLUEFROG

Maybe googling “Alfred AppleScript” helps? Or they provide online explanations on how to incorporate scripts in their workflows.

As I said, I don’t run Alfred.

From what I gather, you need the Powerpack purchase to create a workflow. I believe the workflows have a node for running AppleScripts.

1 Like

Okay, got it. Very lucky to have met you. Have a nice day. :blush:

Here’s how a blank Workflow is created in Alfred:

  • Make sure to select the Workflows tab at the upper left corner
  • Click the + at the bottom and Blank Workflow

Here’s how an AppleScript action is created:

  • Make sure so have the focus on the Workflow content (not on the Workflow in the sidebar)
  • Contextual menu > Actions > Run Script:

  • In Alfred’s script editor window:

    • Open the Language dropdown and select /usr/bin/osascript (AS)
    • Open the dropdown to the right and select with input as {query}

Your Run Script action should look like this:

"{query}" is the input that the script gets from Alfred.

How you like to input a DEVONthink Reference URL into Alfred is up to you (at the moment I can’t imagine a way that would make sense).

Visit the Alfred forum for Alfred questions.

Thank you for your patience and detailed guidance! :heart:

I followed your steps to create the exact same workflow, but I still can’t get it to work. Do I need to create other steps in that workflow?

If you have a ready-made workflow that can be implemented, can you forward it to share? Thanks again!

Of course. The script needs some input:

But that’s not related to DEVONthink. Did you ask in the Alfred Forum?

See, for example, this post on the Alfred forums, and the linked workflow (which I use from time to time).

Stephen

Out of curiosity: Could you also write
if the Path = "" or thePath ends with "/"
since “/” in Unix is equivalent to “:” in HPFS…?
Is this check meant to prevent using an indexed folder?

Yes

Yes, this would work in DEVONthink. But some apps don’t return a folder’s POSIX path with a trailing slash while others do. This makes it impossible to reliably tell from a POSIX path whether it’s a folder’s or a file’s path. A folder’s HFS path always ends with : so this can be used to tell the difference.

Tx. It’s always amazing how complicated apparently simple things can become :wink:

Personally, I’d rather go for something like POSIX file thePath is a folder, though. If that’s at all possible, of course. Can a path of a record in DT even be empty?

Update I found this one

tell application "System Events"
if anItem is package folder or kind of anItem is "Folder" or kind of anItem is "Volume" then
…
end if

where anItem is apparently an alias of a file. Definitely not simpler than your approach.

Thank you for the recommendation. But this doesn’t seem to work for entering DT’s URL in Alfred. :exploding_head:

Does this seem like something that can’t be fixed? :face_with_monocle:

Sorry - it was the best general Alfred DT workflow I could find.

Stephen