Closed kiryph closed 2 years ago
I'll look into this doc later in detail. But a quick question is, can these APIs be restricted to a certain app? Or does it just replace the key globally?
Hi there, I have looked into hammerspoon and its functionality provided, but it seems that it can't perform the functionality we want by using xlib. If I missed something welcome to re-open the issues and discuss with me, thanks!
... can these APIs be restricted to a certain app?
Yes, it is possible to change keys only for a specific app. See
I have tried it myself and came up with following hammerspoon init.lua
using https://github.com/knu/hs-knu/blob/master/chord.lua for key chords:
Install the used knu.chord
as following:
$ git clone https://github.com/knu/hs-knu ~/.hammerspoon/knu
Main credits go to Gilles Castel and his https://github.com/gillescastel/inkscape-shortcut-manager from where most code was adapted to lua.
As reference for the key chords I add the original picture from https://castel.dev/post/lecture-notes-2/ but with the key chords included in the picture.
I did not add the “ergonomic” rebindings x
, w
, f
, and shift+z
. This should be possible in Inkscape itself.
This setup also misses the bindings t
, shift+t
, a
, shift+a
, s
, and shift+s
. Since I encountered issues I did not pursue these.
hs.window.filter.windowUnfocused
is not reliable
I also use yabai. yabai signals could be helpful for the first issue. Possibly the second issue can be resolved with a different implementation of keychords compared to knu.chords.
Currently, I have no plans to push this further. If someone else finds/has found a stable solution for macOS, I would be happy to hear about it.
Ok, it seems to me that this is at least a useable solution. I need to dive into it and see how can I fix those issues you mentioned. That may need some time, I'll update what I get if I have any breakthroughs.
The author of knu.chord
has suggested to use Karabiner Elements for capturing the overlapping key chords. I have come up with following complex_modifications for Karabiner Elements using a jsonnet
file.
The jsonnet
tool can be installed via $ brew install jsonnet
.
Converting the .jsonnet
file into the json file for Karabiner Elements can be done as follwoing
$ jsonnet karabiner-inkscape.jsonnet > ~/.config/karabiner/assets/complex_modifications/karabiner-inkscape.json
Then enable in Karabiner Elements UI the complex modifications.
hs.ipc.cliInstall()
to install the cli command hs
.~/.hammerspoon/init.lua
following:Cool, I'll certainly look into this. Are there any known bugs for this?
Btw, since I'm now going to move on to a bigger project, I apologize that I can't discuss the detailed implementation and configuration for Inkscape with you. Just a spoiler, I'm planning on integrating LaTeX with all these drawing tools with a more modern UI and faster renderer into a single IDE, so we can then all relax and not worry about these weird workaround after this.
Are there any known bugs for this?
Not that I am aware of. However, it is not battle tested.
Just a spoiler, I'm planning on integrating LaTeX with all these drawing tools with a more modern UI and faster renderer into a single IDE, so we can then all relax and not worry about these weird workaround after this.
I am looking forward hearing about it.
Also thank you for creating this repository.
I will close this issue even though a solution with hs.eventtap
could still be done. E.g. this would reduce the number of required tools: I have now three background programs with overlapping feature set:
Just out of curiosity, since I'm thinking about trying your implementation for usability (and also for my own convenience), I'm here for some detailed implementation.
It seems that after following all the configurations you mentioned, the keybinding doesn't work as expected. For now, I have installed
Seems to me that you're using Yabai for defining keybinding? Since I'm using Amethyst, if this is the case, I can try Yabai instead.
Most likely the NSPasteboard UTI is different. Since Inkscape does not define them, macOS chooses dynamical UTI strings INCORRECT (see following comments)"dyn.ah62d4rv4gu80w5pbq7ww88brrf1g065dqf2gnppxs3xu"
.
Can you create a simple rectangle in Inkscape and copy it to the clipboard:
Without putting anything on the clipboard (i.e. copy following snippet to the terminal before you copy the rectangle), run on the command line (requires $ brew install jq
)
hs -c "hs.json.encode(hs.pasteboard.readAllData(), true)" | jq 'to_entries[] | select( .value | contains("<inkscape:clipboard") ) | .key'
which returns for me
"dyn.ah62d4rv4gu80w5pbq7ww88brrf1g065dqf2gnppxs3xw425trz2he3pxsrw0k"
"dyn.ah62d4rv4gu81k3p2su11a5dbrf1a"
"dyn.ah62d4rv4gu80w5pbq7ww88brrf1g065dqf2gnppxs3xu"
"dyn.ah62d4rv4gu80c6durvy0g2pyrf106p52fz7gw6a"
I suspect the dynamic UTIs are all different for you. INCORRECT (see following comments)
If you want to the see the content in the different pasteboards, run
hs -c "hs.json.encode(hs.pasteboard.readAllData(), true)" | jq 'to_entries[] | select( .value | contains("<inkscape:clipboard") ) | [.key, .value]'
So you have to change the following line in the lua init: INCORRECT (see following comments)
hs.pasteboard.writeDataForUTI("dyn.ah62d4rv4gu80w5pbq7ww88brrf1g065dqf2gnppxs3xu", svg)
Yup, what I have is the following:
"dyn.ah62d4rv4gu80w5pbq7ww88brrf1g065dqf2gnppxs3xu"
"dyn.ah62d4rv4gu81k3p2su11a5dbrf1a"
"dyn.ah62d4rv4gu80c6durvy0g2pyrf106p52fz7gw6a"
"dyn.ah62d4rv4gu80w5pbq7ww88brrf1g065dqf2gnppxs3xw425trz2he3pxsrw0k"
So basically, I just change that line with the third (corresponds to what you put in that line) dynamic UTIs?
Updates I can run it successfully. I'll test it for several days and try to put them in this repo. Or if you think you can create a pull request and make your own contribution (as I think it's more appropriate since you create this by yourself and I don't like to steal others' works), feel free to do it. If you think putting them nicely is quite time-consuming, you can simply put all the necessary files into the inkscape folder, and I'll try to write some nice documentation about this.
I can run it successfully.
I am glad to hear this.
I compared the dynamic UTIs from your and mine post. They are actually identical only the order is different:
❯ cat a.txt
"dyn.ah62d4rv4gu80w5pbq7ww88brrf1g065dqf2gnppxs3xw425trz2he3pxsrw0k"
"dyn.ah62d4rv4gu81k3p2su11a5dbrf1a"
"dyn.ah62d4rv4gu80w5pbq7ww88brrf1g065dqf2gnppxs3xu"
"dyn.ah62d4rv4gu80c6durvy0g2pyrf106p52fz7gw6a"
❯ cat b.txt
"dyn.ah62d4rv4gu80w5pbq7ww88brrf1g065dqf2gnppxs3xu"
"dyn.ah62d4rv4gu81k3p2su11a5dbrf1a"
"dyn.ah62d4rv4gu80c6durvy0g2pyrf106p52fz7gw6a"
"dyn.ah62d4rv4gu80w5pbq7ww88brrf1g065dqf2gnppxs3xw425trz2he3pxsrw0k"
❯ diff -s <(sort a.txt) <(sort b.txt)
Files /dev/fd/11 and /dev/fd/18 are identical
So my assumption that the dynamic UTIs are actually arbitrary values set by macOS, when Inkscape is run or a copy is done for the first time, is incorrect. This is actually good news: the script should work fine on different systems without having to change the value.
I'll test it for several days and try to put them in this repo. Or if you think you can create a pull request and make your own contribution.
Right now I do not have the time to create a PR with a well written explanation with figures. So I do not mind when you put it into this repo (if it successfully works for you).
Currently, I tend to fallback to create tikz pictures which are time consuming as you know due to habit and the desire to make it perfect. Hopefully with a more productive Inkscape setup I will stop investing too much time in tikz pictures.
(as I think it's more appropriate since you create this by yourself and I don't like to steal others' works)
Do not worry. I was happy to find your repo and was interested in a macOS solution myself. If there would have been a solution, I have to admit that I probably would have used it right away.
Ok, then I'll try to doc this as detailed as I can, and I'm glad that this works well without bugs. The issue is reopened as an enhancement now, I'll close it after I did all the documentation.
Best.
I finally have time to document this setup, and I think it's good to have you as one of the collaborators since this is basically from you!
@sleepymalc Did you have a look at http://www.hammerspoon.org/docs/hs.eventtap.html to replace xlib on macOS?