Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'fix for column view bug' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
fix for column view bug
Authored by: mzs on May 25, '06 08:15:56PM
I liked this hint a lot, so I improved it. First of all I made it so that I can have the Finder select files with international characters in them. Also I made it so that the compiled AppleScript and the shell script are in the same file. The methods for doing this are detailed in this hint. I also figured-out a work around for the column view bug and I cleaned-up it up a bit.

First create this Makefile:


.SUFFIXES : .applescript .scpt

.PHONEY : install

TARGET = sf
PREFIX = /usr/local
BINDIR = ${PREFIX}/bin

${TARGET} :

install : ${TARGET}
	mkdir -p ${BINDIR}
	ditto -rsrc $< ${BINDIR}

.applescript.scpt : ; osacompile -o '$(subst ','\'',$*)'.scpt -- '$(subst ','\'',$<)'

% : %.scpt %.shosa
	ditto -rsrc '$(subst ','\'',$*)'.scpt '$(subst ','\'',$@)'
	chmod a+x '$(subst ','\'',$@)'
	cat -- '$(subst ','\'',$*)'.shosa > '$(subst ','\'',$@)'
Be sure that every place it looks like there are eight spaces at the beginning of a line is in fact a single tab character in the Makefile otherwise make will choke.

Here is the contents of the shell script portion, sf.shosa:


#!/bin/sh

# Add -a in the arguments to keep the current selection of the front most
# window of the Finder selected while dealing with args of the command line.

usage() {
        echo "Usage: ${0##*/} [-a] [--] filename [ filename... ]" >&2
        exit 1
}

errexit () {
        echo ${0##*/}: "$1" >&2
	usage
}

case $# in
    0)
        errexit "too few arguments"
        ;;
esac

addtocurrentselection=''
case "$1" in
    -a)
	addtocurrentselection=1
	shift
        ;;
    --)
	shift
        ;;
esac
export addtocurrentselection

case $# in
    0)
        errexit "too few arguments"
        ;;
esac

{
        case "$1" in
            /*)
                arg=$1
                ;;
            *)
                arg=$PWD/$1
                ;;
        esac

        echo -nE "$arg"
        shift

        for arg in "$@"; do
                case "$arg" in
                    /*)
                        ;;
                    *)
                        arg=$PWD/$arg
                        ;;
                esac

                echo -ne '\x00'; echo -nE "$arg"
        done
} | /usr/bin/osascript -- "$0"
Finally here is the AppleScript half of the hint, sf.applescript:

-- Read the arguments from stdin so that international
-- characters do not get munged.
set argv to do shell script "/bin/cat"

-- Break-up the arguments into a list.
set AppleScript's text item delimiters to ASCII character 0
set argv to argv's text items
set AppleScript's text item delimiters to {""}

-- See if we create a new selection or add to the current selection.
if (system attribute "addtocurrentselection") is "" then
	set sel to {}
else
	tell application "Finder" to set sel to selection as list
end if

set found to false
repeat with ritem in my argv
	set pf to POSIX file ritem
	
	try
		-- Coercing to an alias will check to see if it exists.
		-- Using item works for folders, files, aliases, etc.
		set fpf to item (pf as alias) of application "Finder"
		set found to true
		set end of my sel to fpf
	end try
end repeat

-- No reason to do anything in the Finder unless some item existed.
if found then
	tell application "Finder"
		-- In column mode, if only folders are selected, the
		-- naive approach does not work as expected. The
		-- selection will only be the last folder of the window.
		--
		-- Therefore a work-around is used. For each window
		-- which is in column view, we retarget it to its parent
		-- and set it to icon view. Then we restore the windows
		-- to column view.
		--
		-- The only problem with this approach is that if the
		-- parent of the item is itself in column view then it
		-- may now be in icon view (depending on if the Finder
		-- has any other Windows open of the parent and when
		-- which which window is closed). I use column view so
		-- rarely that this isn't really a problem.
		set cvl to {}
		repeat with ritem in my sel
			reveal ritem
			
			set fw to front window
			if (current view of fw) is column view then
				set tg to target of front window
				set target of fw to parent of tg
				set current view of fw to icon view
				
				-- tuck-away the window so we can restore
				-- it to column view later.
				set end of my cvl to contents of fw
			end if
		end repeat
		
		-- Select the the items in the Finder.
		select my sel
		
		-- Now restore the windows that were in column view.
		repeat with ritem in my cvl
			set current view of ritem to column view
		end repeat
		
		-- bring the Finder to the front.
		activate
	end tell
end if

return
Type make sf to build sf and type sudo make install to install the sf script into /usr/local/bin. Then sf works just like the script in the hint. This should work in 10.3 as well as 10.4, but I have only tested it on 10.4. I think I will be using this a lot and the original hint was a clever idea.

[ Reply to This | # ]
one more bit
Authored by: mzs on May 25, '06 08:32:36PM

You do not need to use "Current_path:" in the sf script. All arguments can be relatie or absolute. For example, this will work:

sf ~ /Library .



[ Reply to This | # ]