1

I want to create an automator service that copies the full smb:// path of a folder or file (like you would get from + + + C)

The reason the shortcut isn't enough is for all those "older people" (no offense intended) that can't remember shortcuts or don't want to use them at all (the typical rightclick -> copy instead of + C users).

So far I got the POSIX path but how do I transform it to my correct smb:// path?

on run
    tell application "Finder"
         set theItem to selection as string
    end tell
    set posixForm to POSIX path of theItem
    set the clipboard to posixForm
end run

So this path /Volumes/someFolder/someSubFolder/ would become this smb://Server/someFolder/someSubFolder/

8
  • What are you going to do if the "older people" (no offense intended) select more than one file? You should change set theItem to selection as string to set theItem to first item of (selection as alias list) so you do not have to worry about those older people! :) Commented May 25, 2021 at 14:29
  • Thank you! But I still need the translation to smb
    – jona
    Commented May 25, 2021 at 15:37
  • The smb path is going to depend on the name of the share. How about asking us about what you're actually trying to achieve rather than how you think you'll achieve it?
    – Tetsujin
    Commented May 25, 2021 at 15:43
  • Well, I want this path /Volumes/someFolder/someSubFolder/ to become this one smb://Server/someFolder/someSubFolder/ (or for the full story: Right click folder -> MyService -> smb path to clipboard
    – jona
    Commented May 25, 2021 at 15:51
  • You'll probably need to URL Encode some characters and spaces, however, here is a link to some example AppleScript code that you may find helpful, although it only encodes spaces. Commented May 25, 2021 at 16:37

1 Answer 1

1

You may need to URL Encode some characters and spaces, however, here is some example AppleScript code that you may find helpful, although it only encodes spaces:

tell application "Finder" to ¬
    set theItem to the first item of ¬
        the (selection as alias list)

set posixForm to POSIX path of theItem

set {TID, AppleScript's text item delimiters} to ¬
    {AppleScript's text item delimiters, " "}
set foo to text items of posixForm
set AppleScript's text item delimiters to "%20"
set foo to foo as string
set AppleScript's text item delimiters to "/"
set foo to text items 3 thru -1 of foo
set foo to foo as string
set smbForm to "smb://server/" & foo as string
set AppleScript's text item delimiters to TID

set the clipboard to smbForm

Notes:

Have a look at Encoding and Decoding Text in the Mac Automation Scripting Guide.



Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .