set theFolder to (choose folder)
tell application "System Events"
set jsonName to name of first file of theFolder whose name extension is "json"
set newJPGName to text 1 thru -5 of jsonName & "jpg"
set name of first file of theFolder whose name extension is "jpg" to newJPGName
end tell
A thing of beauty. Simple and efficient. Is there a way to apply the same script to a number of folders in the directory rather than selecting them one by one?
This version handles every subfolder in a folder selected by the user:
set topFolder to (choose folder with prompt "Select the folder containing the folders you wish to process …")
tell application "System Events"
set theSubfolders to topFolder's folders
repeat with thisSubfolder in theSubfolders
set jsonName to (name of first file of thisSubfolder whose name extension is "json")
set newJPGName to text 1 thru -5 of jsonName & "jpg"
set (name of first file of thisSubfolder whose name extension is "jpg") to newJPGName
end repeat
end tell
This one allows the user to select several folders in the initial dialog:
set theFolders to (choose folder with prompt "Select the folder(s) you wish to process …" with multiple selections allowed)
tell application "System Events"
repeat with thisFolder in theFolders
set jsonName to (name of first file of thisFolder whose name extension is "json")
set newJPGName to text 1 thru -5 of jsonName & "jpg"
set (name of first file of thisFolder whose name extension is "jpg") to newJPGName
end repeat
end tell
Neither script contains any error checks to make sure the folders contain both of the required files.