Jump to content

Modify workflow behavior based on current app


Recommended Posts

Is there an easy way with Alfred Workflows to change the behavior based on the current app?

I'm writing a workflow that generates a code snippet, and based on the foremost app (Slack vs code editor, mainly), I'd like to add Markdown code formatting (```…```) around the code snippet before pasting into the current app (in addition to copying to clipboard).

 

What would be the easiest way to do this? Thanks!

Link to comment

You cannot do it with Snippets, but you can do it with Workflows. You can use AppleScript to detect the frontmost app, and then act accordingly:

tell application "System Events" to return name of first process whose frontmost is true

Link to comment
8 hours ago, deanishe said:

It will also only work via Hotkeys, not Keywords. If you have Alfred's window open, then Alfred is the frontmost application.

 

Just tested it and it’s not what I see. It’s working as expected via Keyword. It makes sense: you activate the Keyword, Alfred closes and move to the first connection (Run Script), which by the time it runs sees a different app as the frontmost.


But if you can get Alfred to detect itself as the frontmost app, I’d be interested in how, because I was never able to do it (I tried when trying to fake the now native repeat functionality of Script Filters).

Edited by vitor
Link to comment

@vitor There is a new Snippet Trigger workflow object coming very soon which carries the same "focused app" variable option that hotkeys do.

 

This will essentially allow you to dynamically create an auto expanding text snippet based on the currently focused app :)

Link to comment

@Andrew Does that mean we’ll be able to type a bit of text and it’ll act as an External Trigger for a Workflow? Big thumbs up to that — that’s the feature I want more from snippets! Well, that and for the snippet search to also search its contents. I saw the latest update added content search to snippets but only in Alfred Preferences, so I’m guessing that might’ve laid the foundation to also search snippets when in the viewer?

Link to comment
1 hour ago, vitor said:

@Andrew Does that mean we’ll be able to type a bit of text and it’ll act as an External Trigger for a Workflow? Big thumbs up to that — that’s the feature I want more from snippets!

 

If you update to the latest pre-release, the snippet trigger is now in - and yep, it means type some text in any app and away you go :)

Link to comment

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...