Jump to content

CommandRun — Run terminal commands without opening one, on the current Finder window


Recommended Posts

You may find this useful. If you set your terminal application to 'Custom' in Alfred's settings, then you can do something like the below. It runs the shell command in the current terminal without starting up a new terminal window. I use iTerm2, if you're using Terminal.app the AppleScript will be slightly different.

 

on alfred_script(q)
	tell application "iTerm"
		activate
		
		try -- We don't need error messages
			set miniaturized of windows to false
		end try
		
		try
			set _session to current session of current terminal
		on error
			set _term to (make new terminal)
			tell _term
				launch session "Default"
				set _session to current session
			end tell
		end try
		
		tell _session
			write text q
		end tell
	end tell
	tell application "System Events"
		set visible of process "iTerm" to true
	end tell
end alfred_script
Link to comment

You may find this useful. If you set your terminal application to 'Custom' in Alfred's settings, then you can do something like the below. It runs the shell command in the current terminal without starting up a new terminal window. I use iTerm2, if you're using Terminal.app the AppleScript will be slightly different.

 

I’ve seen that code of yours before (in fact, I’d like to be able to do a variation on it), but it still has a fundamental difference — it needs the terminal, which means it’ll still make you wait, if you do not have it open.

Even though I run a lot of commands, I do not like to keep the terminal open at all times. To me, if it’s open it means it’s doing something, which is one of the clues I use while I work. This workflow scratches a specific itch, when I want to run quick commands, but waiting for the terminal to start is annoying.

Link to comment
  • 3 weeks later...

Update.

 

It will now detect your default shell, and if it is bash or zsh, it will source the appropriate files (which means it should now get your export PATHalias, and what else you might have there).

Link to comment
  • 1 month later...
  • 2 months later...

Great workflow. Would be very useful to me. But unfortunately I can't seem to get this to work on OSX Mavericks. Anything idea?

 

One of the biggest challenges to make this workflow and its “sibling” work is that Alfred does not read your PATH and other things that your terminal does when starting. Different users also have different shells and configurations, which makes it harder to set this up in a way that works for everybody. This last update addresses those issues, in some form.

 

Can you please tell me what is your default shell (bash, zsh, other), where it’s located (are you using /usr/bin/zsh/, or /usr/local/bin/zsh, for example), what command you’re trying to run that fails, and how did you install it (is it a system command, or did you get it from homebrew or some other means)? Basically, the more details, the better.

Link to comment

 

One of the biggest challenges to make this workflow and its “sibling” work is that Alfred does not read your PATH and other things that your terminal does when starting. Different users also have different shells and configurations, which makes it harder to set this up in a way that works for everybody. This last update addresses those issues, in some form.

 

Can you please tell me what is your default shell (bash, zsh, other), where it’s located (are you using /usr/bin/zsh/, or /usr/local/bin/zsh, for example), what command you’re trying to run that fails, and how did you install it (is it a system command, or did you get it from homebrew or some other means)? Basically, the more details, the better.

I'm running Mavericks, latest DP (legit I'd like to add). 

 

Shell:

/bin/bash (out-of-the-box)

GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
Copyright © 2007 Free Software Foundation, Inc.
 
Finder:
select my homefolder
 
Command (nothing works): 
touch HelloWorld.txt
/usr/bin/touch HelloWorld.txt
 
I do have HomeBrew installed, but I assume that's not relevant for the command above.
 
Your help is greatly appreciated!
Link to comment
  • 6 months later...

Big update.

CommandRun is now consolidated into RunCommand. Support for csh and tcsh was dropped, and support for bash and zsh was greatly improved, including loading of aliases, following lordheart’s report. If you use this, please download the other workflow instead, as it does the same (but improved) and more.

Edited by Vítor
Link to comment
  • 8 months later...

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