Slash Boxes
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 ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Friday January 05, 2007
01:54 PM

OS X: new terminal window in current directory

[ #32086 ]

Jut thought this might prove useful for some folks. I know I borrowed this code from somewhere but, uncharacteristically, I didn't paste the URL in with the code, so I can't credit the source (I recall hacking the code, but I still can't claim credit).

If you're running OS X and you open a new terminal window, it's handy if it opens in the same directory as the one you're currently working in. The following script allows this (if you know of a better way, please let me know).

# Open a new terminal in the cwd

set thePath to "$CWD"
set myPath to (POSIX file thePath as alias)
    tell application "Terminal"
        do script with command "cd \"" & thePath & "\""
    end tell
end try

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • For users, it's simply:

    xterm &
  • do script with command "cd \"" & thePath & "\""

    Pray that the current directory path never contains any shell metacharacters other than spaces.

  • I don't use Terminal much, I prefer iTerm. But, for Terminal:

    use Cwd;
    use Mac::Glue;
    (my $cwd = cwd()) =~ s/'/'\\''/g;
    my $term = new Mac::Glue 'Terminal';
    $term->do_script(with_command => "cd '$cwd'");

    For iTerm:

    my $iterm = new Mac::Glue 'iTerm';
    my $term = $iterm->make(new => 'terminal');
    $term->Launch(session => 'default');
    $term->obj(session => 1)->write(text => "cd '$cwd'");

    • I found this through a search, but ended up with my own version [] using pbcopy / pbpaste on a one-liner.

      echo `pwd` | pbcopy; osascript -e "tell application \"Terminal\" to do script \"cd \\\"`pbpaste`\\\"\""