Browser window –- Newbie Question --

Hello.

I’m very new to Applescript studio and have a question that’s probably simple to answer, but I can’t seem to figure it out.

I have been using the browser examples in the developer folder.
What I want is to get the file path of the selected file in the browser window, so I can do some useful things with it.

The only changes I did was to insett this lines with code in the end:
on clicked theObject
display dialog selected cell of theObject of browser “browser” of window “main” as string
end clicked

This gave me an error.

I’ve tried all kinds of methods to do this but nothing seems to work.

Any help and examples would be great.
Thanks in advance

The browser script:

(* ==== Properties ==== *)

property diskNames : {}

(* ==== Event Handlers ==== *)

– Initialize various items here

on launched theObject
tell application “Finder”
set diskNames to name of every disk as list
end tell

set path separator of browser "browser" of window "main" to ":"

tell browser "browser" of window "main" to update

end launched

– Return the number of rows for the given column

on number of browser rows theObject in column theColumn
set rowCount to 0

if (count of diskNames) > 0 then
	if theColumn is 1 then
		set rowCount to count of diskNames
	else
		tell browser "browser" of window "main"
			set thePath to path for column theColumn - 1
		end tell
		
		tell application "Finder"
			set rowCount to count of items of item thePath
		end tell
	end if
end if

return rowCount

end number of browser rows

– This is called whenever a cell in the browser needs to be displayed.

on will display browser cell theObject row theRow browser cell theCell in column theColumn
if theColumn > 1 then
tell browser “browser” of window “main”
set thePath to path for column theColumn
end tell
end if

tell application "Finder"
	if theColumn is 1 then
		set cellContents to displayed name of disk (item theRow of diskNames as string)
		set isLeaf to false
	else
		set theItem to item theRow of item thePath
		
		if class of theItem is folder or class of theItem is disk then
			set isLeaf to false
		else
			set isLeaf to true
		end if
		
		set cellContents to (displayed name of theItem as string)
	end if
end tell

set string value of theCell to cellContents
set leaf of theCell to isLeaf

end will display browser cell

(** my code under **)
on clicked theObject
display dialog selected cell of theObject of browser “browser” of window “main” as string
end clicked

It looks like a bug. This should work to get the path to the selected object but it causes an error:

You could back into it starting from the displayed column and working backwards until you’ve built the full path:

HTH,
Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]