Droplet to change to tif

I thought i could handle this on my own but i seem to have messed up something
I am trying to create a droplet that changesthe file name from xxx to xxx.tif
but only if there is no extension on the file

I can get the handler to work but how do i specify everything before the extension?

on open theFolder
	repeat with thisItem in theFolder
		tiffer(theFolder) of me
	end repeat
end open

on run
	tell application "Finder"
		display dialog ¬
			"This is a droplet." with icon 1 buttons {"Ok"} default button 1
	end tell
end run

on tiffer(theFolder)
	tell application "Finder"
		activate
		set theseFolderItems to every item in theFolder
		repeat with thisItem in theseFolderItems
			set thisitemname to the name of thisItem
			if name of thisItem does not end with ".tif" then
				set the name of thisItem to thisitemname & ".tif"
				--else
				
			end if
		end repeat
	end tell
end tiffer

Does this work?

on open theFolder
	repeat with thisItem in theFolder
		tiffer(theFolder) of me
	end repeat
end open

on run
	tell application "Finder"
		display dialog ¬
			"This is a droplet." with icon 1 buttons {"Ok"} default button 1
	end tell
end run

on tiffer(theFolder)
	tell application "Finder"
		activate
		set theseFolderItems to every item in theFolder
		repeat with thisItem in theseFolderItems
			set thisitemname to the name of thisItem
			if thisitemname does not end with ".tif" then
				set the name of thisItem to thisitemname & ".tif"
				-- else do nothing because it ends in .tif
			end if
		end repeat
	end tell
end tiffer

i was able to get it to change before but the problem is it just adds the .tif to the file instead of replacing the old extension
in otherwords I “get xxx.jpg.tif”

I see. Well then, you might want to take a look at the information provided by the “info for” command in Standard Additions. Here are a few items that might be helpful in your current scenario.

set file_info to info for (choose file)

set displayed_name to displayed name of file_info -- name displayed by the Finder.
set extended_name to name of file_info -- file name plus extension (if extension is present).
set name_ext to name extension of file_info -- file extension only (if extension is present)
set ext_hidden to extension hidden of file_info -- Indicates if the file's extension is displayed in the Finder (if extension is present)

If it was my script, I’d probably use “info for” to gather information and Finder to modify the file name if needed, but I haven’t checked to see if the Finder provides the same information. If it does, it would probably be better to use the Finder for all of it. :slight_smile:

Upon further investigation, I’ve found that the Finder provides all of the needed info. Maybe this will work as desired. I tested various elements of this but not the entire script.

on open theFolder 
   repeat with thisItem in theFolder 
      tiffer(theFolder) of me 
   end repeat 
end open 

on run 
   tell application "Finder" 
      display dialog ¬ 
         "This is a droplet." with icon 1 buttons {"Ok"} default button 1 
   end tell 
end run 

on tiffer(theFolder)
	
	set desired_extension to "tif" -- change this to work with other extensions
	
	tell application "Finder"

		activate
		set theseFolderItems to every item in theFolder
		
		repeat with a_file in theseFolderItems
			set file_extension to name extension of a_file
			set file_name to name of a_file
			set displayed_name to displayed name of a_file
			
			if file_extension is not desired_extension and ¬
				file_name does not end with ("." & desired_extension) and ¬
				displayed_name does not end with ("." & desired_extension) then ¬
				set name of a_file to (file_name & ("." & desired_extension))
		end repeat

	end tell

end tiffer

Rob beat me to the finish. The OSX finder allows retrieval of the part of a file name, the part without the extension. But I must ask: if a file is

myfile.jpg

then changing the extension to

myfile.tif

does not make the file a tif. Instead, it probably won’t open. If you’re changing “.jpg” files to “.tif” files you’ll need Graphic Coverter.

I am generally using this script to change files with no extension to file.tif
but wanted the added feature of forcing the change on files that maybe named file.blah where blah is not neccesarily the extension just a bad habit in namming convention
thanks to all for their input