Move and size a Path Finder window based on stored values

May 22, '09 07:30:00AM

Contributed by: robg

I use Path Finder as a Finder replacement on all my machines; I really like the added features it brings to the table. While reading some other stuff about Path Finder, I stumbled across this thread in the CocoaTech forums. There you'll find a number of AppleScript tidbits for Path Finder, many going back a few years. The one that intrigued me, though, was the last one, by reader "cliff," about a script to move and position a window based on stored size and location info.

To do this (assuming you're using Path Finder 5.x), just create these two AppleScripts:

GetFinderSize

set PrefsPath to (path to preferences as text)
do shell script ("mkdir -p " & quoted form of POSIX path of (PrefsPath & "FinderSize"))
set dataFilePath to PrefsPath & "FinderSize:Finder Window Bounds.dat"
tell application "Path Finder" to set FinderWindowOpen to ((count each finder window) > 0)
if (FinderWindowOpen) then
  tell application "Path Finder" to set theBounds to bounds of front finder window
  set fRef to (open for access file dataFilePath with write permission)
  try
    set eof fRef to 0
    write theBounds to fRef
  end try
  close access fRef
end if
FinderSize
set dataFilePath to (path to preferences folder as Unicode text) & "FinderSize:" & "Finder Window Bounds.dat"
tell application "Path Finder" to set FinderWindowOpen to ((count each finder window) > 0)
if (FinderWindowOpen) then
  set theBounds to (read file dataFilePath as list)
  tell application "Path Finder"
    --PFOpen (path to "cusr" from user domain)
    tell front finder window
      set bounds to theBounds
      set {wLeft, wTop, wRight, wBottom} to bounds
    end tell
  end tell
end if
In the FinderSize script, if you remove the -- from the PFOpen... line, Path Finder will (as long as you're not in your home folder; I couldn't figure out force new window creation in Path Finder) create a new window first, then apply your stored location and size to that new window. Otherwise, this script will move and size the current window. Note that this bit is my own added code, so if it fails, blame me, not the original author.

Create both of those in Script Editor, and save both as Applications (uncheck the Startup Screen box when saving). Drag both to the Path Finder toolbar, and you've got a handy way to create windows of a set size. Each time you run GetFinderSize, the current window's size and position is stored. Then, each time you click on FinderSize, the current window will be moved (or a new window created, depending on if you edited the script) to the stored location, and set to the stored size.

Comments (0)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20090521064633878