Hi, I am desperately trying to concatenate these two APPLESCRIPT codes in order to perform a simple renaming action with a standard dialog box. I am missing something (knowledge) to integrate the whole thing: an APPLESCRIPT error has always returned to me...
Details of the desired action:
1 – Select an ITEM from the Finder, whether it is a File or a Folder and wherever it is on the disk, including the Desktop.
2 – Invoke a dialog box to rename this ITEM.
3a – If the ITEM is a Folder, the dialog box displays its current name and allows the user to enter a new name.
3b – If the ITEM is a File, the dialog box displays its current name, BUT without its extension and this allows the user to enter a new name without changing the extension.
4 – Once the new name has been entered and validated, the dialog box disappears.
5a – If the ITEM was a Folder, it will now have the name entered in the dialog box.
5B – If the ITEM was a File, it will now have the name entered in the dialog box, BUT will have its original extension back.
I already have the same KM macro, but I need an APPLESCRIPT code here.
Here is the first code that arbitrarily assigns the name “newName” to the selected ITEM:
tell application "Finder"
set itemSelection to (item 1 of (get selection) as alias)
end tell
tell application "System Events"
if name extension of itemSelection is "" then
set name of itemSelection to "newName"
else
set name of itemSelection to ("newName" & "." & name extension of itemSelection)
end if
end tell
And here is the second code that gives the possibility to enter a new name, BUT displays the extension for Files:
tell application "Finder"
set itemSelection to selection
repeat with aTemp in itemSelection
set newName to name of aTemp
set newName to text returned of (display dialog "Saisir nom :" default answer newName)
set name of aTemp to newName
end repeat
end tell
Thank you for your attention and above all a very happy new year to all...