Here is some code that I believe should change the extension from an image type to a JPG.
(e.g. Change Image.TIFF to Image.JPG)
But instead it returns a file with a double filename extension. (e.g. Image.TIFF becomes Image.TIFF.JPG).
Why? What am I missing?
property openTypes : {"PDF", "com.adobe.pdf", "BMP", "com.microsoft.bmp", "PICT", "com.apple.pict", "PNG", "public.png", "PSD", "com.adobe.photoshop-image", "TIFF", "public.tiff"}
--Get the artwork file
set theFiles to choose file with prompt "Choose art file(s)" of type openTypes without invisibles
set theType to "JPG"
runTest(theFiles, theType)
on runTest(theArt, theType)
display dialog "theArt is " & theArt
tell application "Finder"
set saveExt to extension hidden of theArt
set extension hidden of theArt to true
set theFolder to (container of theArt) as text
set theNewArt to (theFolder as text) & (displayed name of theArt) & "." & theType
set extension hidden of theArt to saveExt
end tell
display dialog "theNewArt is " & theNewArt
end runTest
By the way, here is some workaround code. But I am curious why the code above does not work as expected:
property openTypes : {"PDF", "com.adobe.pdf", "BMP", "com.microsoft.bmp", "PICT", "com.apple.pict", "PNG", "public.png", "PSD", "com.adobe.photoshop-image", "TIFF", "public.tiff"}
--Get the artwork file
set theFiles to choose file with prompt "Choose art file(s)" of type openTypes without invisibles
set theType to "JPG"
runTest(theFiles, theType)
on runTest(theArt, theType)
display dialog "theArt is " & theArt
set noExtName to removeExtension(theArt as text)
tell application "Finder"
set theNewArt to (noExtName as text) & "." & theType
end tell
display dialog "theNewArt is " & theNewArt
end runTest
on removeExtension(thisName)
if thisName contains "." then
set thisName to (the reverse of every character of thisName) as string
set x to the offset of "." in thisName
set thisName to (text (x + 1) thru -1 of thisName)
set thisName to (the reverse of every character of thisName) as string
end if
return thisName
end removeExtension