Trying to change uppercase suffix to lower case (JPG to jpg)

Hello,

I am trying to use imagecatalog.jsx script built into indesign to make contact sheet. for some reason, any image where the suffix is in uppercase, it will not work.?

I found a script here to change lower to upper case and I am trying to get it work for my purposes by switching the information so that it finds all the uppercase letters and makes them lowercase.

I was not able to get it to run so that it would either ask me for files to to change or allow me to drag a folder on top of it?

Any help would be greatly appreciated.


tell application "Finder"
activate
   	on makeCaseLower(theString)
	set lowercase to "abcdefghijklmnopqrstuvwxyz"
	set UPERCASE to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	set AppleScript's text item delimiters to " "
	set theWords to text items of theString as list
	set AppleScript's text item delimiters to ""
	set newList to {}
	repeat with theWord in theWords
		set chrs to characters of theWord
		set Nchrs to count chrs -- get the number of characters
		repeat with K from 1 to Nchrs
			if (item K of chrs) is in lowercase then
				set olc to offset of (item K of chrs) in UPPERCASE
				set item K of chrs to character olc of lowercase
			end if
		end repeat
		set end of newList to chrs as string
	end repeat
	set AppleScript's text item delimiters to " "
	set theString to newList as string
	set AppleScript's text item delimiters to ""
	return theString
end makeCaseLower
end tell

thanks,
Babs

To change a string from uppercase to lowercase there are two smarter / shorter options.

Either you download and install SatImage osax then you can simply write

set lowerCasedString to lowercase "HELLO"  --> "hello"

or with help from AppleScriptObjC you can use this handler

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

use framework "Foundation"

on toLowerCase(theString)
	return (current application's NSString's stringWithString:theString)'s lowercaseString() as text
end toLowerCase

As you want to change only the file extension this code asks for a folder and changes all “JPG” extensions to “jpg” leaving the base names unchanged. It uses the AppleScriptObjC handler above

set baseFolder to choose folder
tell application "Finder"
	set jpgImages to files of baseFolder whose name extension is "JPG"
	repeat with anImage in jpgImages
		tell contents of anImage
			set name extension to (my toLowerCase(get name extension))
		end tell
	end repeat
end tell

Just in case someone has a use for the handler “makeCaseLower” from the original post I noticed that the first use of UPERCASE in the script was “UPERCASE” (with one P), the the next reference was to “UPPERCASE” (with two P’s). When I corrected the mismatched UPPERCASE reference and removed the handler from the Finder tell block the handler appeared to work correctly.

makeCaseLower("JPG")

on makeCaseLower(theString)
	set lowercase to "abcdefghijklmnopqrstuvwxyz"
	set UPPERCASE to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	set AppleScript's text item delimiters to " "
	set theWords to text items of theString as list
	set AppleScript's text item delimiters to ""
	set newList to {}
	repeat with theWord in theWords
		set chrs to characters of theWord
		set Nchrs to count chrs -- get the number of characters
		repeat with K from 1 to Nchrs
			if (item K of chrs) is in lowercase then
				set olc to offset of (item K of chrs) in UPPERCASE
				set item K of chrs to character olc of lowercase
			end if
		end repeat
		set end of newList to chrs as string
	end repeat
	set AppleScript's text item delimiters to " "
	set theString to newList as string
	set AppleScript's text item delimiters to ""
	return theString
end makeCaseLower

result “jpg”

Hi StefanK and danaeugene…

I am not able to download any software to the work computes, nada…

So I tried this one first:



set baseFolder to choose folder
tell application "Finder"
   set jpgImages to files of baseFolder whose name extension is "JPG"
   repeat with anImage in jpgImages
       tell contents of anImage
           set name extension to (my toLowerCase(get name extension))
       end tell
   end repeat
end tell


But got this error.
error “«script» doesn’t understand the “toLowerCase” message.” number -1708 from «script»

I then tried my original one with the typo but still no go.

set baseFolder to choose folder
tell application "Finder"
	set jpgImages to files of baseFolder whose name extension is "JPG"
	repeat with anImage in jpgImages
		tell contents of anImage
			makeCaseLower("JPG")
			set lowercase to "abcdefghijklmnopqrstuvwxyz"
			set UPPERCASE to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
			set AppleScript's text item delimiters to " "
			set theWords to text items of theString as list
			set AppleScript's text item delimiters to ""
			set newList to {}
			repeat with theWord in theWords
				set chrs to characters of theWord
				set Nchrs to count chrs -- get the number of characters
				repeat with K from 1 to Nchrs
					if (item K of chrs) is in lowercase then
						set olc to offset of (item K of chrs) in UPPERCASE
						set item K of chrs to character olc of lowercase
					end if
				end repeat
				set end of newList to chrs as string
			end repeat
			set AppleScript's text item delimiters to " "
			set theString to newList as string
			set AppleScript's text item delimiters to ""
			return theString
		end tell
	set name extension to (my toLowerCase(get name extension))
		end makeCaseLower
		end repeat
end tell

I get this error:
error “Finder got an error: document file "OBIT_RANDALL.JPG" of folder "test_JPG" of folder "Desktop" of folder "barbarapress" of folder "Users" of startup disk doesn’t understand the “makeCaseLower” message.” number -1708 from document file “OBIT_RANDALL.JPG” of folder “test_JPG” of folder “Desktop” of folder “barbarapress” of folder “Users” of startup disk

Appreciate the help…
Babs

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

use framework "Foundation"

on toLowerCase(theString)
	return (current application's NSString's stringWithString:theString)'s lowercaseString() as text
end toLowerCase

set baseFolder to choose folder
tell application "Finder"
	set jpgImages to files of baseFolder whose name extension is "JPG"
	repeat with anImage in jpgImages
		tell contents of anImage
			set name extension to (my toLowerCase(get name extension))
		end tell
	end repeat
end tell

Good morning StefanK

Worked perfectly!!
Thank you!

And Regards,
Babs

Hello…

OK, I have been using the script and it has been great.

I tried to take it a step further and make every suffix, that I could think of, and have it make it lowercase. This is what I came up with and it seems like it worked, once, maybe twice…but not since.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

use framework "Foundation"

on toLowerCase(theString)
	return (current application's NSString's stringWithString:theString)'s lowercaseString() as text
end toLowerCase

set baseFolder to choose folder
tell application "Finder"
	set jpgImages to files of baseFolder whose name extension is "JPG"
	set tifImages2 to files of baseFolder whose name extension is "TIF"
	set psdImages3 to files of baseFolder whose name extension is "PSD"
	set pngImages4 to files of baseFolder whose name extension is "PNG"
	repeat with anImage in jpgImages
		repeat with anImage2 in tifImages2
			repeat with anImage3 in psdImages3
				repeat with anImage4 in pngImages4
					tell contents of anImage
						set name extension to (my toLowerCase(get name extension))
					end tell
					tell contents of anImage2
						set name extension to (my toLowerCase(get name extension))
					end tell
					tell contents of anImage3
						set name extension to (my toLowerCase(get name extension))
					end tell
					tell contents of anImage4
						set name extension to (my toLowerCase(get name extension))
					end tell
				end repeat
			end repeat
		end repeat
	end repeat
end tell

If anyone could take a look and tell me what I am doing wrong that would be great.
Thanks!!!
Babs

No offense but this is horrible code.

For more than one extension create a list and check if the list contains the extension.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

use framework "Foundation"

on toLowerCase(theString)
	return (current application's NSString's stringWithString:theString)'s lowercaseString() as text
end toLowerCase

set baseFolder to choose folder
set imageExtensions to {"JPG", "TIF", "PSD", "PNG"}
tell application "Finder"
	set jpgImages to files of baseFolder whose name extension is in imageExtensions
	repeat with anImage in jpgImages
		tell contents of anImage
			set name extension to (my toLowerCase(get name extension))
		end tell
	end repeat
end tell

Hello Stefan,

No offense taken :wink:

I have not played with any code for probably 4 years, and wasn’t very good at it then.

But, this is how I am learning… Trying to understand it in digestible pieces. Looking at how you set this up, really helps me to learn.

I really really appreciate everything you and the other community members here do.

Thank you!
Babs