À la bonne Sainte-Force

Tools

Tags

Open Terminal Here

13 July 2012

Dear friend,

Here's a quick Porkcut I've been chopping lately: how to open a terminal window in the folder of the current file you're working on in any application.

This is simple. Just make sure you have Porkcuts running. Go to your home directory, invoke Porkcuts and edit the Porkcuts file. Add this code about where you want :

"Terminal here"
thisDirectory := ((Pork cuts invokedDirectoryURL) path) copy.
item := NSMenuItem alloc init.
item setTitle:'Open Terminal here'.
item setKeyEquivalent:'t'.
item setTarget:[ :sender | 
	NSWorkspace sharedWorkspace openFile:thisDirectory withApplication:'Terminal'.
].
item setAction:#value:.
Pork cuts menu addItem:item.
Write this in the Porkcuts file of your home directory.

Now, just invoke Porkcuts on any file you're working on that's somewhere in your home folder. You should see that menu item and be able to switch to a terminal window like a ninja by chaining ⌘⌥⌃Space (invoke Porkcuts) and ⌘T (open Terminal here).

As you can see, it's just some regular Cocoa written in a weird fashion. Hopefully, I'll be able to present other useful Porkcuts over time, building utility classes (yes, you can write Cocoa classes in Porkcuts files) and improving the whole.

Looking forward to hearing from you,
Hubert Sainte-Force