Jump to content

Get Currently Edited Workflow URI


Recommended Posts

Ref.: Twitter Post

---

 

I have a few complex (and many more simple) Alfred workflows and I keep separate documentation on them in another app. It happens to be Obsidian. When I run the workflow debugger I can get a URL for a component in the workflow, and from that a URI for the workflow. I can put this into my Obsidian note and it gives me a way to reference back to the workflow directly.

 

For example, if I trigger the "Browse Hook Bookmarks" flow in the workflow of the same name for the app Hook, I can extract the URI for the script filter step:

alfredpreferences:workflows>workflow>user.workflow.B012BDA7-3A8B-40FB-9692-48283E21C9AB>F9E79BE7-748B-4D2D-AA7F-547DD6972C86

 

It is a simple matter to then derive the URI for the workflow itself.

alfredpreferences:workflows>workflow>user.workflow.B012BDA7-3A8B-40FB-9692-48283E21C9AB

 

Once I know the workflow ID, I could effectively build the URI myself, but this is simply the most convenient way I have found so far.

 

As noted above, I do make use of the Hook app. I use this to help me create and maintain bidirectional links between resources. In this case, being able to use Hook would allow me to link from the Alfred workflow to my documentation; currently I can only link from the documentation to the workflow, and getting the URI involves a little extra effort on my part. If this doesn't make much sense as to what Hook is doing, their website has a variety of resources to help explain how it all works and fits together - certainly far better than I could explain here.

 

If Hook could get the ID or the full URI for the current workflow programmatically, this would enable it to be used for by Hook for linking/association, and would make things much easier for me 😁

 

Hook uses integration scripts to get information like this from apps, so having an x-callback-url to return the ID, or some AppleScript to get the URI would allow me to create an integration script.

 

I have not as yet been able to determine a way to programmatically retrieve this information for use in a Hook integration script, and so I am posting this as a feature request. But, if there is another way to approach this, I'm more than happy to take an alternative.

 

Thanks in advance for any consideration you might give to this request. 

Link to comment
Share on other sites

1 hour ago, sylumer said:

Once I know the workflow ID

 

That is the name of the Workflow’s directory. If you change that, so does the UID. You can get it easily by navigating to it however is most convenient to you. Or you can make Workflow UIDs (locally) predictable by renaming the directories in a consistent pattern (install with brew install vitorgalvao/tiny-scripts/alfred-workflows-renamer or manually rename them how you see fit) which will make UIDs resilient even if you uninstall and reinstall the Workflow.

Edited by vitor
Link to comment
Share on other sites

43 minutes ago, vitor said:

That is the name of the Workflow’s directory. If you change that, so does the UID. You can get it easily by navigating to it however is most convenient to you.

 

As noted above, I am using the debugger approach simply as the most convenient way to get the URI - I tend to find it fractionally quicker to do than opening finder and it at the terminal (though I could probably script it to generate and put on the clipboard I guess).

 

I have never renamed a workflow directory, so I have never had to change an ID, and I do not foresee a reason occurring where I would want change it. If there ever was (e.g. a case where I could not restore from backup ¯\_(ツ)_/¯ ?), then I would just rename those directories back to the original names to restore the previous functionality.

 

The original request remains that it is the programmatic access to the ID/URI of the workflow currently being edited that to allow Hook to do the bi-directional linking.

Link to comment
Share on other sites

CogSci Apps Corp. co-founder here (Hook app). If Alfred had a bit of AppleScript to get and use a link (name and stable address) to the current resource that would be grand. If the Alfred team finds it is overkill to construct a URL scheme for Alfred's workflows, then on the Hook side, we could construct a subscheme scheme for Alfred, something like hook://alfred/<id>. That would be possible as long as there's a stable ID that is available via automation (along with the item name, which can change), and an AppleScript method to open or show a workflow based on its ID.

 

That would be a nice next step in making these two complementary apps (Hook and Alfred) work even better together.

As  @sylumer mentioned, we've made available a workflow for browsing Hook's bookmark Alfred's.

Link to comment
Share on other sites

  • 10 months later...

@sylumer @LucCogZest In Alfred 5.1 (currently in pre-release) the Workflow Editor now writes a sorted history of selected workflow UIDs to ~/Library/Application Support/Alfred/history.json, ordered latest selected workflow first. There is also reveal workflow in AppleScript which can take said UID to show a workflow. It has an optional configuration boolean to reveal it directly to the configuration.

Link to comment
Share on other sites

Thanks. I think I've got a workaround based on that. It uses a custom Alfred workflow that can be triggered by the existing scheme, but it sounds like @LucCogZest should be able to build a subscheme for Alfred into Hookmark (née hook) to do this without a need for an Alfred workflow working as a middleman.

Link to comment
Share on other sites

Quote

There is a help page about Script Environment Variables which may be of some help.

How? I was asking about a URI scheme, not script environment vars?

 

Quote

There is also reveal workflow in AppleScript which can take said UID to show a workflow. It has an optional configuration boolean to reveal it directly to the configuration.

@vitor Just wanted to say thank you for this. This solved one of the small annoyances I had for a long time, namely getting to the Alfred workflow from Finder or my code editor more conveniently 🥰

 

This JXA snippet will open the workflow corresponding to the front Finder window. Bound it to a hotkey only active in finder :)

#!/usr/bin/env osascript -l JavaScript
function finderFrontWindow() {
    const posixPath = finderWindow => $.NSURL.alloc.initWithString(finderWindow.target.url()).fileSystemRepresentation;
    return posixPath(Application("Finder").finderWindows[0]);
}

function run() {
    const winPath = finderFrontWindow();
    if (!winPath.includes("Alfred.alfredpreferences/workflows")) return "Not in Alfred directory";

    const workflowId = winPath.match(/Alfred\.alfredpreferences\/workflows\/([^/]+)/)[1];
    Application("com.runningwithcrayons.Alfred").revealWorkflow(workflowId);
}


 

Edited by pseudometa
Link to comment
Share on other sites

@pseudometa the prefs' URL scheme isn't a published / fixed scheme (it's been changing and evolving over time).

 

You can however grab the URL path of a preference by using Alfred's ? keyword, finding the item you want in the preferences, then using ⌘C to copy the path. Prepend alfredpreferences:// to the copied link, and you'll have what you're looking for.

Link to comment
Share on other sites

@pseudometa what are you typing into Alfred with the ? search... and what are you seeing in Alfred's results?

 

For example, if I type ?eject into Alfred,  I see this:

image.png

Then if I use ⌘C, I get this: features>system>eject which I prefix alfredpreferences:// and get this:

 

alfredpreferences://features>system>eject

 

This URL scheme (copy and paste it into Alfred and press enter) should open prefs and select that option. The same goes for workflows etc.

 

NOTE FROM FUTURE ANDREW:

 

From 5.1 b2132, the URL scheme and copied path have been updated to prepend navigateto/ so in this example:

alfredpreferences://navigateto/features>system>eject

 

Link to comment
Share on other sites

I get the URIs with your described method just fine; however it seems they only work up to the first `>` for me.

 

alfredpreferences://features or alfredpreferences://workflows works, if I add anything after that, it does not work anymore.

 

 

Link to comment
Share on other sites

@pseudometa the URL is correct... try pasting into Terminal app:

 

open "alfredpreferences://features>system>eject"

 

It doesn't really matter it's not working (pasting) inside of Alfred for this specific use case. I'll take a look under the hood to see what's happening regardless.

 

Cheers,

Andrew

Link to comment
Share on other sites

@pseudometa if you update to the 5.1 b2132 pre-release, I've tweaked the URL scheme to prefix navigateto/ to the path. This is also reflected in the ⌘C on the ? search result. This will make the URL scheme in the example above:

 

alfredpreferences://navigateto/features>system>eject

 

Note If this URL scheme is ever officially supported, it will include navigateto/

Link to comment
Share on other sites

And this this snippet adds a keymap to neovim that open the Alfred workflow for the file you are currently working on. Makes working on workflows so much more convenient 😌

 

vim.keymap.set("", "<D-S-l>", function()
    local parentFolder = vim.fn.expand("%:p:h")
    if not parentFolder:find("Alfred%.alfredpreferences") then
        vim.notify("Not in an Alfred directory.")
        return
    end
    local workflowId = parentFolder:match("Alfred%.alfredpreferences/workflows/([^/]+)")
    local command = ([[osascript -l JavaScript -e 'Application("com.runningwithcrayons.Alfred").revealWorkflow("%s")']]):format(workflowId)
    vim.fn.system(command)
end, { desc = "󰾺 Reveal Workflow in Alfred" })

 

 

Link to comment
Share on other sites

  • 2 months later...

Is there a URI scheme for this?

 

I see you can use, e.g.

 

open alfredpreferences://navigateto/workflows

 

But I couldn't figure out how to "reveal" or jump directly to a specific workflow by it's bundle ID or UUID...

 

edit: nevermind ! I re-read the thread and found the info I was looking for! 🏆

 

open 'alfredpreferences://navigateto/workflows>workflow>user.workflow.F24C147F-7520-433E-99C4-EE677C831A95'

 

Edited by luckman212
Link to comment
Share on other sites

6 hours ago, luckman212 said:

But I couldn't figure out how to "reveal" or jump directly to a specific workflow by it's bundle ID or UUID

 

Use the AppleScript:

 

tell application id "com.runningwithcrayons.Alfred" to reveal workflow "SOMETHING"

 

Or JXA:

 

Application("com.runningwithcrayons.Alfred").revealWorkflow("SOMETHING")

 

Where SOMETHING is the workflow’s UID (folder name) or Bundle ID.

Link to comment
Share on other sites

Thanks @vitor for those!

I edited my post above when I found the URI scheme, in this case I was looking for a way to display a clickable link in my Terminal that directly opened the workflow.

 

Alas, iTerm doesn't seem to like the `>` characters. Maybe I need to URL encode them.

Link to comment
Share on other sites

2 minutes ago, luckman212 said:

Alas, iTerm doesn't seem to like the `>` characters. Maybe I need to URL encode them.

 

The > is used for redirection in a shell, which explains why iTerm wouldn’t make that clickable (correct behaviour) and if you tried that without quoting it you’d likely get a few files created. I’d expect that percenting-enconding it would indeed work.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...