Jump to content

Conditional Action based on MacOS Selection


Recommended Posts

Hi,

I have a number of workflows where I want to perform different actions depending on if there is currently text selected or not.

 

One such example is when I want to enclose the selection by double square brackets if text is selected or position the cursor between empty double square brackets otherwise.

Up to this point my go to way to achieve this is:

 

1. Hotkey Trigger with `Argument: Selection in MacOS`

2. Conditional Action checking if `{query}` is empty

3. a) If it is empty paste `[[{cursor}]]`

    b) If it is not empty paste `[[{query}]]`

 

Problem

What I think happens in step 2 is that Alfred simulates `Cmd+C` and checks if the latest clipboard entry contains text.

In some editors like VS Code and Obsidian, however, `Cmd+C` copies the entire line when there is no selected text in the editor. Therefore, Alfred always concludes that text was selected (since the entire line is added to the clipboard) and case 3 a) is never triggered.

 

Question

Is there a better/smarter way to check if text is selected without simulating a copy action?

 

Thanks!

Link to comment
  • 3 weeks later...

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