Page 1 of 1

AS: Copy file path of selected file in the Finder window

PostPosted: Tue Oct 11, 2022 4:20 am
by roskozmos
Hi all,

I'm trying to send a new e-mail message (without the file) when conditions are met. Then just press CMD-V to paste the file path into a new message.

this is my Hazel rule

Image

for the last step "Run AppleScript" I found this on MacScripter

Code: Select all
tell application "Finder" to set these_items to selection
try
   set macPath to POSIX path of (item 1 of these_items as alias)
   set the clipboard to srchRep(macPath, "/", "\\")
end try

on srchRep(theStr, fndStr, repStr)
   set atid to AppleScript's text item delimiters
   set AppleScript's text item delimiters to {fndStr}
   set tempList to text items of theStr
   set AppleScript's text item delimiters to {repStr}
   set theStr to tempList as string
   set AppleScript's text item delimiters to atid
   return theStr
end srchRep


It works from Scripter Editor but not from Hazel itself. In my System Pref. I enabled "Full Disk Access" and "Accessibility" for Hazel.

Thanks for any suggestions!

Re: AS: Copy file path of selected file in the Finder window

PostPosted: Tue Oct 11, 2022 9:15 am
by Mr_Noodle
Is this an embedded script? You can't have handlers in an embedded script. Note that if you use an external script, you need to add a handler for Hazel to call.

Also, search the forums as there is probably a script that will do this, including adding the filename so you don't have to do the whole copy/paste thing.