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

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

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!
roskozmos
 
Posts: 3
Joined: Fri Nov 05, 2021 7:38 am

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.
Mr_Noodle
Site Admin
 
Posts: 11866
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support