Re: get path of selected file
Re: get path of selected file
- Subject: Re: get path of selected file
- From: Camilla <email@hidden>
- Date: Wed, 3 Apr 2002 23:07:00 +0100
This from Paul Berkowitz
>
try
>
tell application "Finder" to set pathToFile to (item 1 of (get
>
selection)) as alias as string
>
>
on error
>
beep
>
display dialog "There's nothing selected in the Finder." buttons {"OK"}
>
default button 1 with icon 2
>
return
>
end try
>
>
-- display dialog pathToFile
A quick hop and a skip to OS X (ctrl-opt-cmd-X) and I'm happy to say that
the line I posted earlier does work here. And my caveat about activating
the Finder also holds true. (It becomes apparent that the Finder is no
longer in front if you have stuff like Finder-specific DragThing docks
that fail to reappear after the script has run.)
It's also worth noting that if nothing in a window is selected, the
script will not error. In this case, if a window is selected (opaque) the
path to its item will be returned, and if no window is selected, the path
to the desktop.
Turning the script into a droplet and placing it in a finder window
toolbar is another way to go. Not quite so efficient in terms of being
economical with system resources, but very intuitive. And then there's
DragThing.
But back to the menu script. The following will put the path to a
selected item on the clipboard when a single item in the active window is
selected, and will display an appropriate dialog if multiple items or no
eligible items are selected.
set theDesktop to path to desktop
tell application "Finder"
activate
try
set thePath to selection as alias
on error
display dialog "More than one item is selected" buttons {"Sorry"}
default button 1 with icon caution
end try
set theWindow to folder of Finder window 1 as alias
if thePath is not in {theWindow, theDesktop} then
set the clipboard to thePath as string
else
display dialog "No file or folder is selected" buttons {"Sorry"}
default button 1 with icon caution
end if
end tell
This was tested in OS X with AppleScript 1.8.2
Camilla
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.