5

AppleScript for using Kitty in Alfred. This was made for bash, but can easily be...

 1 year ago
source link: https://gist.github.com/willeccles/02228fc54c42942531a072318dcaf82b
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
AppleScript for using Kitty in Alfred. This was made for bash, but can easily be made to work with any shell.

floer32 commented Jun 6, 2019

Thank you for sharing this!

Here is a variant that works for me on zsh. curious if zsh -l would suffice to simplify the rcfile stuffs, but not going to waste time on that laughing

on alfred_script(q)
	do shell script "cd ~;/Applications/kitty.app/Contents/MacOS/kitty /usr/local/bin/zsh -c \"source ~/.zshrc && " & q & ";/usr/local/bin/zsh\""
end alfred_script

Author

willeccles commented Jun 6, 2019

@hangtwenty Coincidentally, I switched to zsh a few months ago and had to update mine as well. Naturally, I completely forgot I ever did this, so this didn't get updated at the same time. Thanks for sharing!

curious if zsh -l would suffice to simplify the rcfile stuffs, but not going to waste time on that

I considered this as well, but having already written the naive way, it seemed like a waste of time to go back and change it.

meseck commented Jun 7, 2019

First of all thank you for this nice little script!

Do you also have a problem when you open something with the "Open Terminal here"? In the beginning, it works fine, kitty opens and changes to the directory, but then Alfred window freezes and will not disappear until you close the new instance of kitty.

Author

willeccles commented Jun 7, 2019

edited

@fools-mate: I ran into that same (sort of) problem when writing an Automator service that allowed me to right click a directory and "Open New Kitty Window Here." The issue is that the Alfred task (or in my case, the Automator service) started the kitty process, and therefore cannot exit until the child kitty process has exited. You need to use nohup to disown the child process, like so:

nohup /Applications/kitty.app/Contents/MacOS/kitty `which zsh` -c "source ~/.zshrc && cd \"$1\"; `which zsh`" > /dev/null 2>&1 &

Note: This script is made specifically for my Automator service, and won't work directly in Alfred. Modify your Alfred script as necessary according to the list below.

This is of course using zsh, but you could adapt the same principle to bash in my original script. In fact, the original script likely needs to be updated to reflect this change, but I don't use the "Open Terminal Here" thing in Alfred (@hangtwenty: you might want to change your script if you need this functionality). The basic idea is this:

  1. Use nohup to disown the child process (nohup [...])
  2. Redirect output to /dev/null (> /dev/null 2>&1)
  3. Background the process (the & at the end)

Also, in my script, you might have noticed I used which zsh here and there. This is because I have more than one zsh installed and rather than fix the problem I just made sure the right zsh is the one in the path and I don't have to remember the path myself if I just use which zsh. Ignore that part.

meseck commented Jun 7, 2019

edited

That was a quick and extensive response, thanks!

It tried the command in the terminal and it works fine but when I try to exchange the line in Alfred, it don't work anymore.
What do I wrong? I have no experience in AppleScript.

Btw. nice little trick to use which zsh.

Author

willeccles commented Jun 7, 2019

@fools-mate: If you can post your AppleScript here, I can probably help you a bit better. The one I just posted is not for use in Alfred, it's for the Automator Folder Action thing that I made, which would cause it not to work, as it's specialized for that purpose. However, if you follow the general steps I listed, you should be able to get to a working solution. If not, post your script here and I'll take a look when I can. Apologies for the misleading explanation, I'll update it so that any future readers aren't confused.

meseck commented Jun 7, 2019

Ah ok, I thought this solution would be also a fix for the problem in Alfred.

I just tried to exchange the one line in Alfred, this was really naiv. sweat_smile

on alfred_script(q)
	do shell script "nohup /Applications/kitty.app/Contents/MacOS/kitty `which zsh` -c "source ~/.zshrc && cd \"$1\"; `which zsh`" > /dev/null 2>&1 &"
end alfred_script

Author

willeccles commented Jun 7, 2019

edited

@fools-mate: This is an adapted version of the original (for bash). Try this and let me know if it works for you! I haven't tested it since I'm at work, but this should do it for you.

on alfred_script(q)
	do shell script "cd ~; nohup /Applications/kitty.app/Contents/MacOS/kitty /bin/bash -c \"source ~/.bashrc && " & q & ";/bin/bash\" > /dev/null 2>&1 &"
end alfred_script

meseck commented Jun 7, 2019

I tried it with zsh and it works great! tada
Thank you.

Author

willeccles commented Jun 7, 2019

@fools-mate: No worries! Glad it works for you. I'll update the original script in a moment to reflect this change.

aahung commented Jun 26, 2019

Current script will open another instance of kitty.app (extra icon in Dock)

Author

willeccles commented Jul 2, 2019

@aahung I am pretty sure this is a kitty preference, and I haven't noticed this issue before. Not sure what to tell you.

pyrho commented Mar 23, 2020

If you want to open a new tab within an existing Kitty instance I came up with this: https://gist.github.com/pyrho/d2f4fe152eb8113b1956edd6d7456862, it's a bit more troublesome to set up, but nothing too hard ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK