Jump to content
christian_alares

Change default Terminal to Hyper.is ?

Recommended Posts

Hi!

I just discovered this terminal application: https://hyper.is/

I find it appealing and I would like to change the default Alfred behaviour to this app.

 

For example when I browse för files in Alfred and press "Open Terminal Here".

This seems to be editable in settings but I'm not sure what to write in the AppleScript section.

 

See this little video to understand more what I want to achieve:

 

Share this post


Link to post

As @vitor said, Hyper is not scriptable (there's no applescript dictionary to make it works reliably without keystrokes). However, as a workaround, Hyper is able to open folder and file and it would set it's path to that folder. So, here is what I would do to make it reliable and fast:

 

on alfred_script(q)
	do shell script "open -a Hyper " & text 4 thru -1 of q
end alfred_script

 

Just copy & paste this script in the custom script section in Features > Terminal / Shell of Alfred preferences and this should work

 

Hope this helps!

Edited by GuiB
edit script

Share this post


Link to post

@christian_alares, I just thought I should give a more complete script in case you want a script that work with Alfred prefix command to run a terminal command also. I mean, if you want to do something else than using the Open Terminal Here command. Here is a script that would work for both way of actioning the command:

 

on alfred_script(q)
	if (text 1 thru 2 of q) is equal to "cd" then
		do shell script "open -a Hyper " & text 4 thru -1 of q
	else
		do shell script "open -a Hyper ~"
		delay 1
		tell application "System Events" to keystroke q & return
	end if
end alfred_script

 

As @vitor said, this is not the best way since we need to insert a delay command for the keystrokes (the "delay 1" inside here), but seems to be quite great on my side (you may need to play with the delay time if there's a problem on your side). Also, I've use "open -a Hyper ~" in the second method so a new window is opened without using the keystroke method with delay. You may want to change the default path if you want (this would set you in your home directory, but change the "~" to something else if you prefer)

 

--- Update

I mention that this is not an optimal way, but I mean that mainly for the second method (when sending a command to Hyper). This is still speedy for the "Open Terminal Here" command and is the same as my first script above

Edited by GuiB

Share this post


Link to post

Here is an updated version

 

I wanted to test to find a way so the script wait that the application is ready instead of a definite time before sending the keystrokes. With this version it should be faster and less error prone. Best!

 

on alfred_script(q)
	if (text 1 thru 2 of q) is equal to "cd" then
		do shell script "open -a Hyper " & text 4 thru -1 of q
	else
		do shell script "open -a Hyper ~"
		set appOpen to false
		set nbrOfTry to 0
		delay 0.5
		repeat
			try
				tell application "System Events"
					if exists (window 1 of process "Hyper") then
						set appOpen to true
						exit repeat
					end if
				end tell
			end try
			set nbrOfTry to nbrOfTry + 1
			if nbrOfTry = 20 then exit repeat
			delay 0.5
		end repeat
		if appOpen then tell application "System Events" to keystroke q & return
	end if
end alfred_script

 

Edited by GuiB

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...