Friday, November 24, 2017
  • Index
  •  » Automator
  •  » Mac Contextual Menu for AFP Path Without Spaces

#1 2017-06-23 06:05:04 pm

acenright
Member
Registered: 2017-06-23
Posts: 2

Mac Contextual Menu for AFP Path Without Spaces

Hi yall,

My team requires an Automator service that will allow us to copy file paths from within OS X Finder such that they always start with "afp://server-name/" instead of "/Volumes/server-name/" BUT ALSO replaces all spaces with "%20".

Right now, we are using the following code, which does replace the first space in a given string, but does not replace all spaces.

Applescript:

on run {input, parameters}
set output to {}
repeat with f in input
set end of output to replace(POSIX path of f, "/Volumes/Brand Design", "afp://nycp-afp01/Brand%20Design")
end repeat
set text item delimiters to linefeed
set the clipboard to (output as text)
end run
on replace(input, search, replace)
set text item delimiters to search
set ti to text items of input
set text item delimiters to replace
ti as text
end replace

Any help you can provide will be HUGELY appreciated; thanx!

A.

Browser: Safari 603.2.4
Operating System: Mac OS X (10.10)

Offline

 

#2 2017-06-23 07:10:00 pm

leonsimard
Member
From:: Montreal, Canada
Registered: 2009-09-27
Posts: 526

Re: Mac Contextual Menu for AFP Path Without Spaces

Your replace method needed a little fix, text item delimiters are sensitive. It's common practice to save the current one and put it back after use to not derail other scripts.

Try this:

Applescript:

on run {input, parameters}
   set OldTID to text item delimiters
   set output to {}
   repeat with f in input
       set end of output to my replace((POSIX path of f) as string, "/Volumes/Brand Design", "afp://nycp-afp01/Brand%20Design")
   end repeat
   set text item delimiters to linefeed
   set the clipboard to (output as string)
   set text item delimiters to OldTID
end run

on replace(stringToSearchAndReplace, theSearchString, theReplaceString)
   set returnString to stringToSearchAndReplace
   set oldASTID to AppleScript's text item delimiters
   
   set AppleScript's text item delimiters to theSearchString
   set tempString to text items of stringToSearchAndReplace
   
   set AppleScript's text item delimiters to theReplaceString
   set returnString to tempString as string
   
   set AppleScript's text item delimiters to oldASTID
   
   return returnString
end replace

Browser: Safari 603.2.4
Operating System: Mac OS X (10.10)

Offline

 

#3 2017-06-23 07:16:49 pm

acenright
Member
Registered: 2017-06-23
Posts: 2

Re: Mac Contextual Menu for AFP Path Without Spaces

Thank you! I'll review.

In the meantime, might this work?

Applescript:

on run {input, parameters}
set output to {}
repeat with f in input
set f to replace(POSIX path of f, "Volumes/Brand Design", "afp://nycp-afp01/Brand Design")
set f to replace(f, " ", "%20")
set end of output to f
end repeat
set text item delimiters to linefeed
set the clipboard to (output as text)
end run
on replace(input, search, replace)
set text item delimiters to search
set ti to text items of input
set text item delimiters to replace
ti as text
end replace

A.

Model: MBP 10.12.5
Browser: Safari 603.2.4
Operating System: Mac OS X (10.10)

Offline

 

#4 2017-06-23 07:18:42 pm

leonsimard
Member
From:: Montreal, Canada
Registered: 2009-09-27
Posts: 526

Re: Mac Contextual Menu for AFP Path Without Spaces

It has the same general issues as with the first script. Try mine and see if it helps. If there's still some issues, I'll help you with those.

Offline

 
  • Index
  •  » Automator
  •  » Mac Contextual Menu for AFP Path Without Spaces

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)