Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

pudge (1)

pudge
  (email not shown publicly)
http://pudge.net/
AOL IM: Crimethnk (Add Buddy, Send Message)

I run this joint, see?

Journal of pudge (1)

Friday January 19, 2007
02:06 AM

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

[ #32199 ]

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'");

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'");

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.