vitor Posted April 8, 2013 Share Posted April 8, 2013 (edited) This was now consolidated into RunCommand, so you should download that instead. Edited April 24, 2014 by Vítor Link to comment
ctwise Posted April 8, 2013 Share Posted April 8, 2013 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
vitor Posted April 8, 2013 Author Share Posted April 8, 2013 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
vitor Posted April 16, 2013 Author Share Posted April 16, 2013 Minor update. It now supports notifications. Link to comment
vitor Posted May 4, 2013 Author Share Posted May 4, 2013 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 PATH, alias, and what else you might have there). Link to comment
vitor Posted June 27, 2013 Author Share Posted June 27, 2013 Update. It now uses the frontmost Finder window as the starting point of the command (if none is open, it defaults to your home directory). Link to comment
vitor Posted July 4, 2013 Author Share Posted July 4, 2013 Update. It now uses a more “natural” directory detection. Commands start in the frontmost Finder window, and if you have none selected or open, they’ll start on the Desktop. Link to comment
vitor Posted September 25, 2013 Author Share Posted September 25, 2013 Long due update. It now saves a file, and then executes it, solving some issues. Link to comment
vitor Posted September 30, 2013 Author Share Posted September 30, 2013 Update. It goes back to using bash, instead of zsh (a small remnant of previous tests). Link to comment
vitor Posted October 2, 2013 Author Share Posted October 2, 2013 Update. More efficient way to run commands, and support for more shells. Link to comment
jordic Posted October 2, 2013 Share Posted October 2, 2013 Great workflow. Would be very useful to me. But unfortunately I can't seem to get this to work on OSX Mavericks. Anything idea? Link to comment
vitor Posted October 2, 2013 Author Share Posted October 2, 2013 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
jordic Posted October 3, 2013 Share Posted October 3, 2013 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
vitor Posted October 3, 2013 Author Share Posted October 3, 2013 That really is weird, being touch such a basic command. Could you please redownload and install the workflow, just so we’re sure it’s really the latest version? There were some recently that kind of broke some things. Link to comment
jordic Posted October 3, 2013 Share Posted October 3, 2013 I've just installed a newly downloaded copy. That didn't help. I'll add debugging to the workflow scripts to hopefully see what happens. Link to comment
jordic Posted October 3, 2013 Share Posted October 3, 2013 Your script creates a command file in the workflow folder. The issue on my machine is that my shell can't execute that file using ./command. I've changed the script so it creates the command file in /tmp. That did the trick. Link to comment
vitor Posted October 4, 2013 Author Share Posted October 4, 2013 Odd. I have no idea why that happens. Thank you for figuring it out, though, I’ve update the workflow to reflect that change. Link to comment
lordheart Posted April 23, 2014 Share Posted April 23, 2014 bash was still not sourcing ~/.bash_profile so no alias's. the fix for me was changing the tmp/commandRun file creation echo to echo "shopt -s expand_aliases source ~/.bash_profile cd ${dirPath} {query}" > /tmp/commandrun Link to comment
vitor Posted April 24, 2014 Author Share Posted April 24, 2014 (edited) 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 April 24, 2014 by Vítor Link to comment
joshnpowell Posted January 2, 2015 Share Posted January 2, 2015 I'm disappointed to read that tcsh support has been dropped. It's my default shell, and the one I'd like to use with keyword to script, etc. Link to comment
vitor Posted January 2, 2015 Author Share Posted January 2, 2015 (edited) I’ve readded support for tcsh and csh; check RunCommand for those. I’ve removed them at the time for a few reasons, but your comment made me revisit it and make them work again. Edited January 2, 2015 by Vítor Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now