applescript how to remove part of POSIX string

Is there someone how can help me by fixing my apple script? I want to delete or remove /Volumes/ every time I use this script by copying a path on a shared folder.



on ReplaceText(theString, fString, rString)
	set current_Delimiters to text item delimiters of AppleScript
	set AppleScript's text item delimiters to fString
	set sList to every text item of theString
	set AppleScript's text item delimiters to rString
	set newString to sList as string
	set AppleScript's text item delimiters to current_Delimiters
	return newString
end ReplaceText

tell application "Finder"
	set thisFile to selection as alias
	set FilePath to "afp://nas01._afpovertcp._tcp.local/" & POSIX path of thisFile
	set FileURL to ReplaceText(FilePath as string, " ", "%20") of me
	set the clipboard to FileURL
end tell


For example

OUTCOME:
afp://nas01._afpovertcp._tcp.local//Volumes/Office/060

What I want:D:

afp://nas01._afpovertcp._tcp.local/Office/060

Thanks for helping me out

You may try :

on ReplaceText(theString, fString, rString)
	set current_Delimiters to text item delimiters of AppleScript
	set AppleScript's text item delimiters to fString
	set sList to every text item of theString
	set AppleScript's text item delimiters to rString
	set newString to sList as string
	set AppleScript's text item delimiters to current_Delimiters
	return newString
end ReplaceText

tell application "Finder"
	set thisFile to selection as alias
	set FilePath to "afp://nas01._afpovertcp._tcp.local/" & POSIX path of thisFile
	set FileURL to ReplaceText(FilePath, " ", "%20") of me
	set FileURL to ReplaceText(FileURL, "/Volumes/", "") of me
	set the clipboard to FileURL
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 29 octobre 2018 15:42:33

Thats it! Thank you so much!:smiley:

Yvan may I ask you one more question, I was tweaking with another script and it will be more perfect if above script also opens a new email and pasting that line into it. Some part of this script has to be in the one above.

So only add the part that tells to open mail and paste the line into a new email. Do you know what I mean?

It would be very helpfull



activate application "SystemUIServer" -- works around a selection bug
tell application "Finder"
	activate
	set theSelection to (get selection)
	if theSelection is {} then
		display dialog "Nothing selected" buttons {"Cancel"} default button 1
	end if
	set urlList to {}
	repeat with anItem in theSelection
		set end of urlList to URL of anItem
	end repeat
end tell
set {TID, text item delimiters} to {text item delimiters, return}
set urlLines to urlList as text
set text item delimiters to TID

tell application "Mail"
	activate
	make new outgoing message with properties {content:"Link:" & return & return & urlLines, subject:"file link", visible:true}
end tell