Jump to content

Open terminal here, current terminal window?


Recommended Posts

I use iTerm instead of Terminal, so I'm not sure if this code catches all conditions, but you can do this:

  1. Open Alfred Preferences, click the Features tab and click Terminal / Shell in the sidebar.
  2. Set Application to Custom and paste this script in the large textfield:
on alfred_script(q)
    tell application "Terminal"
        if exists window 1 then
            do script q in window 1
        else
            do script q
        end if
        activate
    end tell
end alfred_script

Close Alfred Preferences to save the changes.

 

Note that when you run a Terminal command manually with Alfred (by prefixing it with ">"), it will now also run in the existing window.

Edited by Tsunami
Link to comment

Perfect! I've used a bit of AppleScript I've been using with Emacs for years:

on alfred_script(q)
	tell application "Terminal"
		try
			if (count of windows) is 0 then
				do script q
			else
				do script q in window 1
			end if
			activate
		on error
			beep
		end try
	end tell
end alfred_script

That works a treat: if I already have a Terminal window open it'll send the commands there, otherwise it'll create a new window.

Link to comment
22 minutes ago, Tsunami said:

Open Alfred Preferences, click the Features tab and click Terminal / Shell in the sidebar

 

That makes all Terminal Commands run in the current window, not just the "Open Terminal Here" File Action.

 

That may or may not be what @chrispoole is after. I thought it was worth mentioning, in any case.

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