Simply this script that uses text item delimiters for find/replace?

Hello, Here’s my next ugly script. I’m using a TID find and replace routine to delete the file extension from file names I’m collecting to the clipboard, and it works, but I’m wondering if there is a way to simplify it. Is there an AS way to delete the .jpg extension without finding and replacing with “”? Thanks - Mark


set theSel to (selection of application "Finder")
set pathList to {}
repeat with anItem in theSel
	set the end of pathList to name of (info for anItem as alias)
end repeat
set {TID, text item delimiters} to {text item delimiters, return}

on replaceText(find, replace, pathList)
	set prevTIDs to text item delimiters of AppleScript
	set text item delimiters of AppleScript to find
	set pathList to text items of pathList
	
	set text item delimiters of AppleScript to replace
	set pathList to "" & pathList
	set text item delimiters of AppleScript to prevTIDs
	
	set the clipboard to pathList
	return pathList
	
end replaceText

get replaceText(".jpg", "", "" & pathList & "")

Hi,

there are several solutions, this is one of them


set theSel to (selection of application "Finder")
set pathList to {}
repeat with anItem in theSel
	set {name:Nm, name extension:Ex} to (info for anItem as alias)
	if Ex is missing value then
		set end of pathList to Nm
	else
		set end of pathList to text 1 thru ((offset of Ex in Nm) - 2) of Nm
	end if
end repeat
set {TID, text item delimiters} to {text item delimiters, return}
set pathList to pathList as text
set text item delimiters to TID
pathList

Stefan, That works; I think I can see how you delete the extension by the offset and not by find and replace, and that kills two birds with one stone, since it will delete all file extensions, not just “jpg” that I wrote the first script for. Thanks for the AS lesson. - Mark