I've used a Services extension to copy the path of the Finder selection for eons, so I never noticed it is not installed by default in OS X. I received a recent support question asking for this, so here is the resulting macro.
Select a file in the Finder, and then select Copy Path from the Keyboard Maestro status menu and the selection's POSIX path is copied tot he clipboard. If you select more than one, then they are copies as multiple lines (if its only one, there are no return characters),
Thanks Peter, I too have been using this for a while, since I am a new convert to Keyboard Maestro this is the AppleScript that I had been triggering in the Finder with QuicKeys.
tell application "Finder"
set theWin to window 1
set thePath to (POSIX path of (target of theWin as alias))
display dialog thePath buttons {"Clipboard", "OK"} default button 1
if the button returned of the result is "Clipboard" then
set the clipboard to thePath
end if
end tell
Neat to see another method Keyboard Maestro can do, plus this includes the file itself and not just the folder the file exists in.
One or more items selected in the front window of the Finder (which can be the Desktop).
If there is no selection then the path of the front window if it exists.
If no windows are open then the path to the Desktop.
-ccs
-----------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2010/10/06 06:43
# dMod: 2015/04/27 18:38
# Appl: Finder
# Task: Get posix path of selected items or if none the front window and copy to clipboard.
# Libs: None
# Osax: None
# Tags: @Applescript, @Finder, @Posix, @Path, @Selection
-----------------------------------------------------------------------
try
tell application "Finder"
set fileList to selection as alias list
if length of fileList = 0 then
set fileList to insertion location as alias as list
end if
end tell
if length of fileList > 0 then
repeat with ndx in fileList
set ndx's contents to POSIX path of ndx
end repeat
set AppleScript's text item delimiters to linefeed
set fileList to fileList as string
set the clipboard to fileList
end if
on error e number n
stdErr(e, n, true, true) of me
end try
-----------------------------------------------------------------------
--» HANDLERS
-----------------------------------------------------------------------
on stdErr(e, n, beepFlag, ddFlag)
set e to e & return & return & "Num: " & n
if beepFlag = true then
beep
end if
if ddFlag = true then
tell application "Finder"
activate
set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
end tell
if button returned of dDlg = "Copy" then set the clipboard to e
else
return e
end if
end stdErr
-----------------------------------------------------------------------
I use ⌥⌘C to copy a pathname. If no files are selected then it copies the path of the open window otherwise it copies the path of one or more selected files.
It shows in the Edit menu of Finder when the alt key is pressed.
I’m new to KM so apologies if this isn’t what you are trying to do.
My apologies as I believe I've unintentionally misled you and Emyr! I've
not actually used the prior thread's approach to complete the file copy and
perhaps your responses were provided based upon those actions since the
responses don't quite meet my needs.
I'm simply testing the attached macro to eventually use it to copy movie
files (~ 1 GB) to the "Automatically Add Files To iTunes" library folder.
The problem is the window is still open after the copy completes. Maybe I
should try to use the actions in the original thread to complete my copy
along with your proposed solution or do you have an alternative suggestion?
Please disregard all my previous responses to your suggestion and forgive
all my confusion!!
Your “Pause While Window->Copy” suggestion works perfectly! I simply
needed to add a bit of delay (5 seconds) for the copy (i.e. paste action)
to begin before testing for the (Window->Copy enabled) condition.