Select a File, add an Extension and move to the desktop script issue.

I have created a script to let the user choose a file then it will automatically add the extension and move it to the desktop.

The issue is I keep getting this error :“Finder got an error: Expected a reference.” number -1727. THis is my script any advise would be helpful.


--Select File to recover from Attic
tell application "Finder"
	set TheFile to choose file with prompt "Please Choose the file to recover" default location ("/Users/Shared/AvidMediaComposer/Avid Attic")
end tell

--Add Extenstion
tell application "Finder"
	set selected_items to TheFile
	repeat with f in selected_items
		set ext to the name extension of f
		if the name extension of f is "" and the class of f is document file then
			set the name of f to the name of f & ".avb"
		end if
	end repeat
end tell

--Moves selected item to desktop --
tell application "Finder"
	set selected_items2 to TheFile
	set theFolder to path to desktop folder
	repeat with x in selected_items2
		try
			duplicate x to theFolder
		on error
			display dialog "File with same name already exists on your desktop. Please delete or move and try again." with icon 2
		end try
	end repeat
	
end tell

Hi,

the main problem of the script is that the user chooses one file but the script expects a list of files.
To proceed multiple files use (without Finder tell block)


--Select File to recover from Attic
set TheFile to (choose file with prompt "Please Choose the file to recover" default location alias ((path to shared documents folder as text) & "AvidMediaComposer:Avid Attic:") with multiple selections allowed)

The script throws an error if the folder Avid Attic does not exist

Thank you, its no longer getting the error, however, the script does not add the Extension .avb to the file. Note: the file has no extensions to begin with. It just ends up on the desktop without the extension.


--Select File to recover from Attic
set TheFile to (choose file with prompt "Please Choose the file to recover" default location alias ((path to shared documents folder as text) & "AvidMediaComposer:Avid Attic:") with multiple selections allowed)


--Add Extenstion
tell application "Finder"
	set selected_items to TheFile
	repeat with f in selected_items
		set ext to the name extension of f
		if the name extension of f is "" and the class of f is document file then
			set the name of f to the name of f & ".avb"
		end if
	end repeat
end tell

--Moves selected item to desktop --
tell application "Finder"
	set selected_items2 to TheFile
	set theFolder to path to desktop folder
	repeat with x in selected_items2
		try
			duplicate x to theFolder
		on error
			display dialog "File with same name already exists on your desktop. Please delete or move and try again." with icon 2
		end try
	end repeat
	
end tell

why not


.
set name extension of f to "avb"
.

?

PS: If you want to get and set a property in the same line you must explicitly get it


 set the name of f to (get the name of f & ".avb")

Removed the “if” command and it works now. Thanks