I have looked everywhere in this forum, and haven’t found any solution to my problem. My problem is that I have a folder on my server that every now and then get pictures copied to it. The pictures themselfes lies in folders, i.e.
~/Desktop/Pictures in/TEST/pic1.jpg, pic2.jpg and so forth
The problem is that the folder “TEST” sometimes get odd characterz like “µ”, “√”, “¢” and others. I would like to get rid of those and replace them with lets say “a” or “o”.
You probably need to be using something called text item delimeters to replace characters!
Heres an example:
set theText to "pictur foldr"
set OldDelims to AppleScript's AppleScript's text item delimiters
set AppleScript's AppleScript's text item delimiters to ""
set newText to text items of theText
set AppleScript's AppleScript's text item delimiters to "e"
set newText to newText as text
set AppleScript's AppleScript's text item delimiters to OldDelims
return newText
I would be inclined to use Nigel Garvey’s FindAndReplace version because it is nestable (can be called in its own argument so that more than one find/replace can be accomplished in a single line like
set myNewText to findAndReplace(toFindA, replaceWithB, my findAndReplace(toFindC, replaceWithD, theText))
And, it returns the same class of text as the original (as a result of the “beginning” bit).
on findAndReplace(toFind, replaceWith, theText)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to toFind
set textItems to theText's text items
set AppleScript's text item delimiters to replaceWith
tell textItems to set editedText to beginning & replaceWith & rest
set AppleScript's text item delimiters to astid
return editedText
end findAndReplace
The trick will be to identify the characters you don’t want and their appropriate replacements. Not enough info to pursue that.
This is just a portion of a script I use to rid addresses of diacritical marks. I modified it to show you the possibilities.
Just set the _limitText to ‘yesspace or nospace etc.’. No more funky file names!
Hope this helps,