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.
#!/usr/bin/perl # # 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'; $iterm->activate; my $term = $iterm->make(new => 'terminal'); $term->Launch(session => 'default'); $term->obj(session => 1)->write(text => "cd '$cwd'");
my $term = new Mac::Glue 'Terminal'; $term->do_script(with_command => "cd '$cwd'");