"Open folder in Terminal" for Spotlight or Alfred - macos

Is there any way in Spotlight to have a folder open in a Terminal window, either by providing an "Open in Terminal" option in search results, or (ideally) by holding down a key when selecting a result? Basically the same way holding down command will "Open containing folder" maybe make it so holding option (or whatever key) could "Open in Terminal".
Alternately, is there a way to setup the Alfred app so that it will always open folder search results in the Terminal? that might be even better, then I could use ctrl-space exclusively for opening folders in the Terminal and command-space (Spotlight) for everything else.
The closest thing I can find to anything like these is the "cdto" application, which adds an "Open in Terminal" button to the Finder. This is nice, but being able to do this directly from Spotlight or with a keypress would be much more convenient.

This question is old and you undoubtedly found the answer by now; for the sake of completeness: the latest version of Alfred allows one to search/navigate the filesystem from within Alfred, and take action on the folder or file found. One folder action is "Open Terminal Here", which seems to be what you are asking for.

I've found this to be the fastest method without any external tinkering.
Requirement: need to have iTerm or Terminal in the Dock:
Type the folder name into Alfred / Spotlight
Click and drag the folder that was found into the iTerm / Terminal icon in the Dock

Try this tool:
https://github.com/nmadhok/OpenInTerminal
This is a really handy tool for programmers on Mac as it lets you open the folder directly in Terminal. You can select multiple folders to open them in multiple terminal windows. You can also select files to open the parent directory in Terminal. This application works with Finder as well as without Finder which is a plus!

use this Alfred extension
https://github.com/LeEnno/alfred-terminalfinder
then just lob off the input and set it to a hotkey.. I have one to open the current finder in terminal and vice-versa

#Verboze - I'm still looking for an answer :)
Perhaps it should be migrated to stack exchange or the other one used non-programming topics, such as system administrivia. Though a case could be made that the command line is essential to programming.....
Windows has "Command Prompt Here". Linux has Nautilus' "Open In Terminal". The world's most advanced operating system has nothing (the best I can tell).
For completeness, I did look at the customizable toolbar ('drag your favorites here'; but my favorite is missing). I also found an old Action Script or Automator Script that did not work (the article was old, and it could not be followed).
I did find a program called "CD To...", but its broken. Upon opening the first terminal, the program opens two terminals. I'm not sure what other programming mistakes were made by the developer, and I really don't want to experiment.

Check this: https://github.com/miromannino/alfred-new-terminal-window
It opens a new Terminal/iTerm window in the current space.
Holding the alt key, the new window is also opened opened in the current frontmost Finder folder.
For me that is almost sufficient for my daily work!
Hope it helps!

Related

How to create dock icon for running terminal command in Mac OS

Now I open jmeter using terminal using command: open /usr/local/bin/jmeter
I need it frequently, so I want to create dock icon to run this command.
How can I do it?
I tried to make a right click and choose 'keep in dock' option. However, it disappears when I close the application.
The closest I could get was creating a desktop icon through the following method:
Create a plain text document in TextEdit
Paste the following code in the document
#!/bin/bash
open /usr/local/bin/jmeter
Save the file as fileName.command
Open Terminal and navigate to the directory which you saved the file
Type in chmod +x fileName.command and hit enter
You should now have a shortcut to execute this command! I know this isn't the exact solution you were looking for, but I hope this still solves your problem.
Following E. Zimbelman's answer, you create a .command executable file and then
you can add an icon (drag and drop an icon file on the icon of the properties window of the file (Cmd+I))
change the .command extension to .app
so you can add it the the dock (drag and drop), it's ok if the icon has changed temporarily
and then you change it back to .command
With this you can have any script you like in the .command file and have it on mac's dock.
I suggest you have a look at the answer to this question in the apple stackexchange. It pretty much does exactly what you want (although I have no idea what jmeter does).
The answer is, essentially, use automator to run your script, save the automator job as an app (not a workflow), and drag the resulting object to the dock, once you have it working the way you want.
https://apple.stackexchange.com/questions/73897/how-can-i-launch-a-virtualbox-vm-from-the-dock
or the wayback machine copy:
https://web.archive.org/web/20160921184459/https://apple.stackexchange.com/questions/73897/how-can-i-launch-a-virtualbox-vm-from-the-dock
I needed a simple terminal command to unmount an internal disk which keeps spinning up whilst appearing in Finder to be unmounted. I am running the Mac from an external SSD.
All that was required was to open Script Editor and enter the text:
do shell script "diskutil eject /dev/nameofthedisk"
and then save that as an Application. Drag that to the dock and now I have one click unmounting of the disk when it spins up.

How can i add a Right Click option/options on any specific directory of window

I am creating a directory synch application in java programming application. Now i want to add share option when user right click with in a specific directory, and want to open an dynamic url on clicking that new option. Can anyone help me to find any good solution. Can anyone provide me Registry Script For this task.
An msdn resource on Extending Shortcut Menus will be good for you.
Anyway, I'd like to introduce my own "minimal" example. This opens a gnuplot's wgnuplot terminal at the right-clicked directory after choosing "Open gnuplot here" shortcut.
You can add keys into HKEY_CLASSES_ROOT\Directory\shell. I added HKEY_CLASSES_ROOT\Directory\shell\gnuplot with string (name: (Default)) Open gnuplot here, provided an icon string with the program's icon path, a LegacyEnable empty string and a command key that windows have to execute when clicking. You can reach the right clicked directory name with %V (You can find out more special variables on this Q&A thread at SU). Here's the code that creates the structure:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\gnuplot]
#="Open gnuplot here"
"Icon"="\"C:\\Windows\\icons\\wgnuplot.ico\""
"LegacyEnable"=""
[HKEY_CLASSES_ROOT\Directory\shell\gnuplot\command]
#="\"C:\\Users\\Cron\\Documents\\egyetem\\gnuplot\\bin\\pgnuplot.exe\" -e \"cd '%V'\" -persist"

New OSX User: Opening up a new terminal window in current space(?)

I'm just meddling with OSX after a few years on Linux. There's a lot that I'm liking, but one thing that's slowing me down is that if I run the 'terminal' command via shortcut/spotlight/quicksilver, it whisks me off to any existing terminal in whatever space already has a terminal instance open.
I regularly like to pop up a terminal, run a quick command and then close it again, all the while staying in whatever desktop space I happen to be on.
...So, how do I do that on Mac?
Cheers...
Go to System Preferences -> Exposé & Spaces -> Spaces and check When switching to an application, switch to...
Download this tool called Visor
It lets you quickly get a tabbed drop down terminal using a hotkey like Ctrl-`.
Insanely convenient for working in the shell.
Try this tool: https://github.com/nmadhok/OpenInTerminal
This is a really handy tool for programmers on Mac as it lets you open the folder directly in Terminal. You can select multiple folders to open them in multiple terminal windows. You can also select files to open the parent directory in Terminal. This application works with Finder as well as without Finder which is a plus!

run applescript on 2x-click

OK, this feels like an idiot question, but I'm stuck - I don't know the first thing about AppleScript. I have a .scpt file and I want to double-click it and just have it run, but instead every time I click, it opens up the AppleScript Editor. This feels like it should just be an option on the file, but I'm missing something obvious.
Please help me feel less dumb, thank you.
From the “File” menu, choose “Export”; there’ll be a “File Format” dropdown underneath the file browser. To get a double-clickable application instead of a document, choose “Application”. This will produce a .app bundle like ordinary Mac applications (this will also let you package other resources with your script if you need to). You can choose “Run Only” or not; if you do, then anybody with just the .app won’t be able to edit your script further, since it’ll be compiled. (But if you’re saving a copy as the application, that might be what you want.)
Another option, as per an anonymous user on Ask Different, would be to save/export your file as a “Script” (.scpt) or “Script Bundle” (.scptd), save it in ~/Library/Scripts/, and check “Show Script menu in menu bar” in Script Editor’s preferences.
(If you’re running an old version of OS X, the first version of this answer has the information you’re looking for.)
There's more than one way to do it; i have found this to be the simplest:
In sum, you create an Automator application and place your applescript inside it (easier than it sounds, and it's not a hack either--there's actually a specific Automator action for this). Then when you are finished, you select "File" from the menubar, next "Save As Application", then select a location. Now check there and you'll see the newly-created Automator icon (little white robot holding a grenade launcher).
You can do anything that you would ordinarily do with this application icon--double click to open, drag it to your dock, etc.
Appstorm has created an excellent step-by-step tutorial for building an applescript-embedded automator action. On the page i linked to, the tutorial author has also supplied an Automator script that you can download and use as a template.
While it's certainly not the simplest route, one benefit to running your script from Automator, as doug suggested, is that you can set a hotkey or keyboard shortcut to execute your script if you hide it in an Automator Service (OSX 10.6+). See:
http://blog.fosketts.net/2010/08/09/assign-keyboard-shortcut-applescript-automator-service/
When you save a new script, a menu should appear asking what you want the file name to be, where it will be stored, any tags for it, and what script format you want it to be. There should be 4 scripts formats:
Script
Script Bundle
Application
Text
The script format you want to use would be "Application." This will turn it into a double-click application if its not in the dock.

Open dot-file with dialogue in OSX

Since the GUI-side of OSX treats all dot-files (such as .htaccess) as hidden, it doesn't display them in any of the graphical UI:s, e.g. Finder or the Open-dialogues.
How can I open a dot-file (.htaccess in this case) in a graphical editor, without doing that thing for all hidden files, universally and without going through Terminal.app?
Edit: I'm on Leopard, if that makes a difference.
Edit2: TextWrangler and TextMate seem to have features that allow you to open hidden files, which partly answers my question.
In an "Open File" dialog you can use Command-Shift-. to see dot files.
You could tell Finder to display hidden files as well (enter in Terminal):
defaults write com.apple.finder AppleShowAllFiles TRUE
But that’s not really nice since there are a lot more hidden files. So I recommend to use an editor that allows you to view those in the open dialog like Chuck mentioned.
If you only want to do this for one specific file, you can create a symbolic link to the dot-file. Open up Terminal.app, cd to the directory containing your dot-file, and run
ln -s .htaccess dot_htaccess
Then you should be able to double-click the file dot_htaccess as a regular file, and any edits you make will really go into .htaccess.
TextMate (a really nice text editor for OS X) open dialog has a "Show hidden files" option, and TextWrangler (and its big brother BBEdit) has it has a menu item.
In the command line, for a file named FILE, type:
open -e FILE
The open command will open the file in TextEdit (-e flag). Check out "man open" for more flags (e.g., specify the app to open with -a)
Smultron (another nice OS X editor mentioned in the comment above and similar to TextMate, but free) has an "Open Hidden..." file menu item that works splendidly for this purpose.
Sad news: Smultron is apparently no longer being developed further beyond v3.5.1 (which requires Leopard), according to a post from its author at its homepage: http://tuppis.com/smultron/
jEdit is another free option that has hidden file support: www.jedit.org/users-guide/vfs-browser.html (sorry for the lack of 'http' in the link -- being a new user, my posts are limited to just one link. Alas...)

Resources