(reinventing the wheel, again)
I find that I often need to have the posix path of a file (or multiple files) I select in Finder. So I decided to write a script to do that. Before, I was doing that from the command line: I'd select the file, call a "path" utility I had made for the Terminal, pasted the selection and the utility filled the clipboard with the path after I hit Enter.
Now, I have a path.app Applescript application that I call with Spotlight.
Improvements over the command line thing I had are:
1) I don't have to copy-paste anything :), just selecting items is enough 2) I can select multiple files in a normal Finder window or in a Search window, and that gives me the list of paths 3) If I don't select anything, I get the path to the container window, except in a Search window where there is no notion of container.
It's amazing the amount of time it takes to write a seemingly trivial thing like this when you're not used to write code. The point being, the more you write, the less time it takes...
So, here is the thing. I think I've tested it enough in the path months that I've not forgotten weird edge cases. If you have any comments or suggestions, go ahead.
Jean-Christophe
# This script gets the POSIX path of the Finder selection. # If there is no selection, it gets the container. # If there is 1 selection, it gets the path, without adding a linefeed # If there are multiple selections, all the paths are on a separate line # If there is no selection and no container (search window), an alert is displayed
# The result is put into the clipboard and the data can be pasted wherever needed. # A notification is displayed when the clipboard is available. # The notification only displays the first selected item.
tell application "Finder"
set _selectedItem to selection
try if (count _selectedItem) = 0 then set _selectedItem to POSIX path of (insertion location as alias)
else repeat with i from 1 to ((count _selectedItem) - 1) set _thePath to POSIX path of (item i of _selectedItem as alias) & linefeed set item i of _selectedItem to _thePath end repeat set _thePath to POSIX path of (last item of _selectedItem as alias) set last item of _selectedItem to _thePath end if
set _selectedItem to _selectedItem as text set the clipboard to _selectedItem display notification _selectedItem
on error display notification with title "Select at least one file in the window." end try
end tell
|