Jump to content

Window Switcher Needs Help Being Awesome


Recommended Posts

Hi. I'm a novice programmer and need some help improving a script filter based workflow. I appreciate any guidance users can give.

 

My workflow is a simple cmd-tab-like window switcher for yabai. The script queries all open windows via yabai and then builds the json to filter with jq. The filtered argument is then sent to the script yco-switch-focus which switches the window.

 

 

/usr/local/bin/yabai -m query --windows | /usr/local/bin/jq '{
    "items": [
            .[] |
            .id as $theID |
            .pid as $thePID |
            .space as $theSpace |
            .app as $theApp |
            .title as $theTitle |
                {    
                    "uid": $theID,
                    "type": "default",
                    "title": $theTitle,
                    "subtitle": $theApp,
                    "arg": $theApp,
                    "icon": {
                       "type": "fileicon",
			          "path": ("~/Applications/"+$theApp+".app")
		               },
                    match: $theApp
                 }
       ]
}'

 

The workflow works, but there are areas that can be improved. Hopefully I can implement these with a little help from the community here.

 

Improvements:
1) Adding a fallback element to script filter results that I can use to trigger other Alfred workflows. I found this thread and think it provides a solution, but I don't quite understand how to make it work with my script filter structure.


2) Faster results when calling the script filter. There seems to be a slight delay in populating the script filter that I don't see in other workflows. I'm not sure if this is caused by the Yabai query or if faster workflows use some sort of cache to speed things up. If that's the case, I'm not sure how to implement a similar solution.


3) Sorting results based on usage. Since this is a window switcher, I often use it to jump back and forth between recently used windows. Right now, the recently selected windows sometimes show up at the bottom of the results. I'm not sure how to get them to the top of the list.


4) Combine multiple variables into the argument that I can split when selected and use for advanced functions. Yabai can query a lot of useful information, such as window id, screen id, space id, etc, which I don't currently use because the app name is the only thing associated with the argument. I have experimented by setting arg to $theApp,$id which failed. I suspect this is an easy fix, but I'm just ignorant of how to write it out properly.

 

What do you think? Does anyone feel able to help me out? I've managed to stumble my way in the dark this far. Looking for a bit of light to guide my path to the finish line! Thanks in advance.

 

Workflow: https://www.icloud.com/iclouddrive/0j5gwYB_TDtr5PauhT6vecA7Q#Switcher

Link to comment
On 5/10/2021 at 2:34 PM, brapstallion said:

Adding a fallback element to script filter results that I can use to trigger other Alfred workflows.


I’m unclear on what you’re asking.

 

On 5/10/2021 at 2:34 PM, brapstallion said:

Faster results when calling the script filter. (…) I'm not sure if this is caused by the Yabai query or if faster workflows use some sort of cache to speed things up.


Use time to see how long your command takes to execute. I’m not familiar with Yabai, so I can’t say if it’s slow or not.

 

Presumably you’re getting the window states at each point in time which is ever changing, so there’s nothing to cache.

 

On 5/10/2021 at 2:34 PM, brapstallion said:

Sorting results based on usage.


Keep uid consistent between runs and Alfred will do it for you.

 

On 5/10/2021 at 2:34 PM, brapstallion said:

Combine multiple variables into the argument that I can split when selected and use for advanced functions.


You can set multiple variables into each result item. They will be passed downstream as environment variables.

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