Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Trying to find and replace text in clipboard

I am trying to copy a file path to the clipboard and replace the word "Volumes" with "MyServer". Currently I can get the path and replace the spaces, which is working well. Now I just need to replace that word "Volumes" and I'm having no luck. Here is the code I currently have. Any help would be great.



tell application "Finder"

set sel to the selection as text

set TempTID to AppleScript'stext item delimiters

set AppleScript'stext item delimiters to space

set sel to text items of sel

set AppleScript'stext item delimiters to "%20"

set sel to sel as string

set AppleScript'stext item delimiters to TempTID


set the clipboard to "afp://" & POSIX path of sel

get the clipboard



end tell

OS X Mavericks (10.9.4)

Posted on Feb 26, 2015 11:14 AM

Reply
7 replies

Feb 26, 2015 12:54 PM in response to david from milwaukie

I forgot to insert the 'myserver' text 🙂

I have added a try block to catch the error when Finder has nothing selected, but it files with multiple items selected too! It will need to repeat for each selected item.


tell application "Finder"

try

set sel to the POSIX path of (selection as text)

set res to do shell script "echo " & sel & " | sed 's|/Volumes/|afp://myserver/|''"


set the clipboard tores

get the clipboard

on error

display dialog "Nothing selected, curling up & dying." buttons "OK" default button 1

end try

end tell

Trying to find and replace text in clipboard

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.