PDA

View Full Version : How to go to current Terminal location in PF browser


openmacnews
Mar 20, 2006, 07:53 PM
hi,

i'm fairly certain this is "in here", but searching on "finder open" returns just about everything ...

when in shell/terminal, if i type

open /path/to/dir/

the Finder opens a window of that DIR ... of course, then i can Reveal in PF.

how do i set terminal (Finder?) to "open" a DIR into PF?

thx.

bill
Mar 21, 2006, 10:31 AM
If you use this, it'll open your folder of choice in Path Finder:
open -a Path\ Finder <foldername>
Example: open -a Path\ Finder ~/Documents
will open your Documents folder in Path Finder.

If you want to make it a bit easier, you can use this:
alias pfo="open -a Path\ Finder"
Then you can typepfo <foldername>
to open the folder of your choice.

Even easier, add the alias to your profile.

openmacnews
Mar 21, 2006, 10:39 AM
If you use this, it'll open your folder of choice in Path Finder

thx! the alias works nicely ...

jeremydb
Jan 06, 2007, 06:56 AM
It would be great if there were a way to jump to the current Terminal location (the PF terminal window). That is, I open a terminal window, navigate to /path/to/something/, but now I'd like to do some GUI stuff with the files in this directory. Ideally, I could just hit some key command, return focus to a Path Finder browser window and jump to the current location. Have I overlooked a feature or am I making a suggestion?

Thanks
Jeremy

neilio
Jan 06, 2007, 11:31 AM
This is something I've wanted, too -- I'll make sure Steve has a feature request on his list to add some terminal integration (like a "pfopen" command or something similar).

jeremydb
Jan 06, 2007, 12:19 PM
I use zsh, and was able to do the following:

alias pfopen="open -a 'Path Finder' ."

Dunno how this is done in bash or tsh, but probably there's something similar?

now, typing pfopen opens a new Path Finder window at the current location. I wish I could get it to open a new tab instead, but it's better than nothing.

jb

jeremydb
Jan 06, 2007, 12:58 PM
This is even better - opens in the current window:

alias pfopen="osascript -e 'on run argv' -e 'tell application \"Path Finder\" to select item 1 of argv' -e 'end run' \$PWD"

or this:

alias pfopen="osascript -e 'on run argv' -e 'tell application \"Path Finder\"' -e 'select item 1 of argv' -e 'activate' -e 'end tell' -e 'end run' \$PWD"

which brings PF to the front afterward.

me
Jan 06, 2007, 08:06 PM
AWESOME TIP!

thank you.

This should be put in the pathfinder download as a read me!

quicksketch
Mar 24, 2009, 07:48 PM
Here's a function that you can place in your .zshrc or in .bashrc that should work in either shell:


pfopen () {
if [ "$#" = "0" ]
then
open -a 'Path Finder' `pwd`
else
open -a 'Path Finder' $1
fi
}

masonk
Sep 04, 2009, 12:53 PM
Try getting info on a directory and then in the Open With pane, chose Path Finder and then change all. I don't have to do anything else to have my directories open in PathFinder instead of Finder, from Terminal or anywhere else (except from a Dock alias, for which, according to the documentation, one must change /Applications/Path\ Finder.app/Contents/PkgInfo to contain the string "FNDRMACS".)

But let's take it one step further. Why not use the integrated terminal and nifty script that I'm including? It implements what seems like the most sane behavior for the built-in terminal in Path Finder. Specifically this is a way to keep the working directory in sync with the directory that the PF gui is showing. This is modified from an earlier bash script that I found on the net, but that one did not work out of the box and did not achieve automatic syncing.

Stash this code in your ~/.profile (or ~/.bash_profile).
There is one caveat, which is that I'm using the ruby appscript bridge in one of the functions and so you must have the rb-appscript gem installed on your computer. It would be possible to rewrite this function into pure applescript, but I don't care to do it.


#The following functions are for use with PathFinder's
#built-in terminal
#they allow me to synchronize the directory that I'm viewing in PathFinder
#with the working directory on the terminal below, using AppleScript hooks.

export OS="$(uname -s)"
if [ "$OS" == "Darwin" ]; then
# find out which app launched this terminal
export LAUNCHING_APP=`osascript << EOS
tell application "System Events"
set frontapp to the name of every process whose visible is true and frontmost is true
return frontapp
end tell
EOS`
fi

# if under Path Finder, cd to the current PF directory
function pff()
{
if [ "$OS" == "Darwin" ]; then
if [ "$LAUNCHING_APP" == "Path Finder" ]; then
# get new path
pf_path=`osascript << EOS
tell application "Path Finder"
set the window_list to the Finder windows
set front_window to item 1 of window_list
set front_path to the POSIX path of the target of the front_window
return front_path
end tell
EOS`
if [ ! -z "$pf_path" ]; then
cd "$pf_path";
fi
fi
fi
}


# pft: change Path Finder window to current Path Finder Terminal
function pft()
{
if [ "$OS" == "Darwin" ]; then
if [ "$LAUNCHING_APP" == "Path Finder" ]; then
ruby -e '
require "rubygems"
require "appscript"
pf = Appscript.app("Path Finder")
window = pf.finder_windows.get[0]
window.reveal(ENV["PWD"])
'
fi
fi
}

function cd ()
{
# Automatically change the PathFinder window when cding
if [ "$LAUNCHING_APP" == "Path Finder" ]; then
builtin cd "$*";
echo $*;
pft;
fi
if [ "$LAUNCHING_APP" != "Path Finder" ]; then
builtin cd "$*";
fi
}


This code gives you two new commands to use in the built-in terminal, pff and pft. pff changes the terminal's working dir to the gui's working dir, and pft goes the other way. The coup de grāce is the cd command. When in PathFinder, the cd command will do its normal thing and then call pft to change PathFinder's GUI. The only thing that doesn't work automatically is using the gui's navigation techniques to get around; in these cases you have to call pff once you switch back to the terminal. I couldn't find an appropriate callback that would allow me to automate the synchronization of this potential way of navigating, so I use cd to get around now.