Yabai: [request/question] similar behaviour to flashfocus

Created on 16 Sep 2019  路  9Comments  路  Source: koekeishiya/yabai

Hello,
I was wondering if something on the lines of Flashfocus could be implemented in yabai.
Or otherwise, if is there a way to make the Mac os compositor (quartz?) behave similarly.

question

Most helpful comment

You can implement this at a user-level assuming that the scripting-addition is installed (necessary to modify opacity).

Hook something like the following script to the window_focused signal.

# window_alpha_fade wid opacity duration

wid=$YABAI_WINDOW_ID
dur=0.1
aOut=0.2
aIn=1.0
echo "window_alpha_fade $wid $aOut $dur" | nc -U /tmp/yabai-sa_$USER.socket
sleep $dur
echo "window_alpha_fade $wid $aIn $dur" | nc -U /tmp/yabai-sa_$USER.socket

PS: untested, may not work exactly as is, but you get the gist

All 9 comments

You can implement this at a user-level assuming that the scripting-addition is installed (necessary to modify opacity).

Hook something like the following script to the window_focused signal.

# window_alpha_fade wid opacity duration

wid=$YABAI_WINDOW_ID
dur=0.1
aOut=0.2
aIn=1.0
echo "window_alpha_fade $wid $aOut $dur" | nc -U /tmp/yabai-sa_$USER.socket
sleep $dur
echo "window_alpha_fade $wid $aIn $dur" | nc -U /tmp/yabai-sa_$USER.socket

PS: untested, may not work exactly as is, but you get the gist

What's the difference between nc-ing the string to the socket and going the "yabai -m config" way?
Is yabai -m just a wrapper?

You can use nc to communicate with the scripting addition directly in order to use it in ways that are not exposed through yabai -m.

Ok, I wrongly assumed that window_alpha_fade was a method usable with yabai -m (now I guess that window_alpha_fade is used by window_opacity_duration).
Is there a way to know which submethods are accessible via nc?

You can find the implementation here: https://github.com/koekeishiya/yabai/blob/master/src/osax/payload.m#L820

This is not a part of the yabai API and is very much internals that could be subject to change at any point if I deem it necessary, or whatever.

Alright, thank you very much for the insights.

Hello, sorry if i reopened this but i'm having trouble passing the variable $YABAI_WINDOW_ID to an external script.
as of now i'm doing
action="/path/to/script.sh $YABAI_WINDOW_ID" and in the script i have a line for debugging
wid=$1; echo $wid | terminal-notifier
but it just return an empty string.

I modified the script that you wrote down and it works as intended (tested with hardcoded window id) but as soon as i try to pass in the variable i get and empty notification from the debug string.

Is this the intended way to work with the event's arguments in an external script and i'm just bad at shell scripts?

Use single quotes instead of double quotes. You're not evaluating the variable $YABAI_WINDOW_ID in your action, but rather in your config file.

It works, thanks again. Damn quotes get me everytime.

Was this page helpful?
0 / 5 - 0 ratings