Hi @peavine
Yes, you are right that the content of my first message and some sentences in a later one can be misleading.
The aim I am looking for is to rename (for example by adding a string at the end) both the selected files in a folder and the name of the folder itself that contains them.
It is true that in another message I mentioned the possibility that the action could be extended to some other selected files contained in subfolders of the first folder. It was not my intention to create confusion with that, but rather an assumption of mine that if the case raised in the first message was solved, maybe the solution could also be extended to selected files located in subfolders of the first mentioned folder.
I tried your first version of the script and told you that I found bugs in the execution. You replied that you were working on the detected bugs.
So far I had not tested your first corrected script nor the last one I just saw.
The first corrected script fails very often and rarely achieves the goal.
on appStringEndOfNamItem(sel, _text)
tell application "System Events"
repeat with x from 1 to count sel
set ext to name extension of item x of sel -- error -- The compiler highlights "name extension".
--System Events has detected an error: Unable to obtain aliases "Macintosh HD:Users:âŚ".
-- However, sometimes it works well. It has erratic behaviour.
set nCompl to name of (item x of sel)
The latest version of your script has a much higher hit rate, but it also fails sometimes. It is able to succeed even when the selection simultaneously spans the base folder, files in the base folder, even sub-folder and selected files located in the sub-folder.
repeat with anItem in renameList
set itemExtension to name extension of anItem -- error. Get text appended to the end of the folder name.
-- Finder has detected an error: Cannot get alias "Macintosh HD:Users:...".
--
set itemName to name of anItem
if itemExtension > "" then
set nameNoExtension to text 1 thru text item -2 of itemName
set name of anItem to nameNoExtension & theText & "." & itemExtension
else
set name of anItem to itemName & theText
end if
end repeat
Errors, when they occur, are flagged by the compiler when handling the file extension name.
I made some screenshots where you can see in the Finder the errors in the results, but I donât know how to send them to you through the post.
Finally, I thought I saw in some of your comments some anger on your part towards me.
Please forgive me if you have felt offended in any way. It is not my intention to offend you, quite the contrary.
Thank you very much for your help and time.