applescript - How to rename a folder and some of its content from a text returned variable -


what want find , replace command applescript. know can use namechanger , other programs takes many steps. i'm efficiency.

tell application "finder"     set selected_items selection     set jobnum text returned of (display dialog "job number:" default answer "")     set name of document folder selection jobnum (*if did work rename entire folder isn't want.  goal replace "12345" value of jobnum*) end tell 

sample folder structure (i can't submit images yet because need 10pts)

main folder: 12345_sample job folder  - 12345_d.ai  - 12345_p.ai  - proofs  - working files       - 12345.ai 

try script:

set jobfolder choose folder prompt "choose job folder:"  tell application "finder"     set rootname jobfolder's name     set searchstring findsearchstring(rootname)     set replacestring text returned of (display dialog ("this script search files contain " & searchstring & ".  please enter replacement text , click ok.") default answer searchstring)     set every file in (jobfolder's entire contents)     repeat onething in         if ((onething's name) text) contains searchstring             set onething's name replace_chars(((onething's name) text), searchstring, replacestring)         end if     end repeat     set jobfolder's name replace_chars(((jobfolder's name) text), searchstring, replacestring) end tell --------------------------------- on replace_chars(this_text, search_string, replacement_string)     set astid applescript's text item delimiters     set applescript's text item delimiters search_string     set item_list every text item of this_text     set applescript's text item delimiters replacement_string     set this_text item_list string     set applescript's text item delimiters astid     return this_text end replace_chars --------------------------------- findsearchstring(txt)     set astid applescript's text item delimiters     set applescript's text item delimiters "_"     set sst txt's text item 1     set applescript's text item delimiters astid     return sst end findsearchstring 

this affect filenames within initial chosen folder, not subfolder names. @ end, changes name of chosen folder.

the renaming handler based on code @ bottom of this page


Comments