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


Click here to return to the 'Another approach' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Another approach
Authored by: wgscott on May 27, '06 09:54:24PM
This is something I came up with that uses code from Gary Kerbaugh's posd function, a function that returns the path of the frontmost finder window.


function selectfile {
osascript << eof
try
tell application "Finder" to set the source_folder to (folder of the front 
window) as alias
on error -- no open folder windows
	set the source_folder to path to desktop folder as alias
end try

set thePath to (POSIX path of the source_folder as string)
set result to thePath

set PosixFile to thePath & "/" & "$@"

set CompletePath to POSIX file PosixFile

tell application "Finder"
	select CompletePath
end tell
eof
}

Typing the command

selectfile My File.txt


will select the file My File.txt in the frontmost finder window, and if no finder window is open, it will select it on the desktop. It also works for files that don't have spaces in their names. :)

[ Reply to This | # ]