Stupid Mac::Glue Tricks: new terminal window in Finder window

| | Comments (0)
Ovid had a code snippet for opening a new terminal window in the current Terminal directory. It was in AppleScript, and because it's what I do, I rewrote it in Mac::Glue, and also rewrote it to work in iTerm, whch is what I use.

I have for awhile wanted something similar for the Finder, but never got around to it. That is, open a terminal for whatever Finder window I am in. So ... here it is.

# Open a new terminal in the Finder cwd
use Mac::Files;
use Mac::Glue ':all';
my $finder = new Mac::Glue 'Finder';
my $cwd = $finder->prop(target => window => 1)->get(as => 'alias');
$cwd ||= FindFolder(kUserDomain, kDesktopFolderType); # default to Desktop
$cwd =~ s/'/'\\''/g;
my $iterm = new Mac::Glue 'iTerm';
my $term = $iterm->make(new => 'terminal');
$term->Launch(session => 'default');
$term->obj(session => 1)->write(text => "cd '$cwd'");

If you want to use Terminal, replace the lines about iTerm with these:

my $term = new Mac::Glue 'Terminal';
$term->do_script(with_command => "cd '$cwd'");

Leave a comment

<pudge/*> (pronounced "PudgeGlob") is thousands of posts over many years by Pudge.

"It is the common fate of the indolent to see their rights become a prey to the active. The condition upon which God hath given liberty to man is eternal vigilance; which condition if he break, servitude is at once the consequence of his crime and the punishment of his guilt."

About this Entry

This page contains a single entry by pudge published on January 18, 2007 11:06 PM.

Sigh ... More WA Democratic Evilness, This Time Fixing Court Elections was the previous entry in this site.

PudgeTunes: Under the Sea is the next entry in this site.

Find recent content on the main index or look in the archives to find all content.