Need help w/User Input Box for renaming multiple files

Is it possible to modify this script to have an input box open and allow a user to type in the name they want to replace with.

tell application “Finder”
set targetFiles to every file of (entire contents of (choose folder)) whose name contains “Track”
repeat with currentFile in targetFiles
set newFileName to my getNewFileName(name of currentFile)
set name of currentFile to newFileName
end repeat
end tell

on getNewFileName(oldName)
set {oldDelims, my text item delimiters} to {my text item delimiters, “Track”}
set name_parts to text items of oldName
set my text item delimiters to “_”
set newName to name_parts as string
set my text item delimiters to oldDelims
return newName
end getNewFileName

For example: I want a user input box to allow me to type in “Celine” and then replace every file that contains the phrase “Track” with “Celine.”

Thanks. :shock:

Will this help?

set DaDialog to display dialog "Enter your data" default answer ¬
	"The Artist" buttons {"Cancel", "Use This Data"} ¬
	default button "Use This Data" with icon 1 ¬
	--giving up after 30

set UserData to text returned of DaDialog

if button returned of DaDialog is "Use This Data" then
	--process UserData
	display dialog UserData
end if

I’ve tried adding that to my script, but it just hangs after I choose the folder. Perhaps I have added it into the wrong place. Where should I place that within the script? I am such a novice, I am still trying to learn the correct heirarchy for writing scripts. Thanks for your help!

Okay, I have it working. I didn’t realize that the script would require entering the data for every file. I had copied it from another scripter on the board with a similar need. Can I alter the script so that it will allow me type the data only once and then use it to replace the phrase “Track” in every file in the folder? Thanks so much!

Give this a shot.

--first identify the folder containing the files to process
--replacing "path:to:the:folder:" accordingly
--and get the list of the files in that folder
set Files2Process to list folder "path:to:the:folder:" as list
-- get the user data
set DaDialog to display dialog "Enter your data" default answer ¬
	"The Artist" buttons {"Cancel", "Use This Data"} ¬
	default button "Use This Data" with icon 1 ¬
set UserData to text returned of DaDialog

if button returned of DaDialog is "Use This Data" then
	repeat with x from 1 to count of items in Files2Process
		--process the files with the UserData 
		tell me to display dialog ("Processing: " & item x of Files2Process & return & ¬
			"using: " & UserData)	
	end repeat
end if

Lemeeno
Jeff Case