Hallo Gerd,
versuchs mal hiermit:
property newSuffix : ""
global tmpNameOhneSuffix, cleanList
on Initialize()
set my newSuffix to text returned of (display dialog "Bitte neues Suffix angeben:" with icon 1 default answer my newSuffix)
set cleanList to {{".", ""}}
end Initialize
on Finalize()
activate
display dialog "Fertig."
end Finalize
on ProcessAFile(aFile)
tell application "Finder"
if (name of aFile as string) is in {".DS_Store", "Icon"} then return false
set tmpName to name of aFile as string
set tmpNameOhneSuffix to suffixDel(tmpName) of me as string
set destFileNameNew to my nameCleaner(tmpNameOhneSuffix, my cleanList) as string
try
set name of aFile to destFileNameNew & my newSuffix
on error
my FehlerSuffix()
end try
end tell
--
-- file process
--
end ProcessAFile
on FehlerSuffix()
activate
display dialog "Die Datei " & tmpNameOhneSuffix & " wurde nicht bearbeitet. Prüfen!!" giving up after 5
end FehlerSuffix
on nameCleaner(nameToClean, RepList)
set tmpDelimiters to my text item delimiters
repeat with dels in RepList
set my text item delimiters to item 1 of dels
set nameToClean to every text item of nameToClean
set my text item delimiters to item 2 of dels
set nameToClean to nameToClean as string
end repeat
set my text item delimiters to tmpDelimiters
return nameToClean
end nameCleaner
on ProcessAFileOrFolder(theFile)
--
-- This handler processes a file or a folder. If its a folder, we recure
-- into ScanAFolder. If its a file, we call the user handler "ProcessAFile"
-- to deal with the file
--
set theFileInfo to info for theFile
if folder of theFileInfo then
ScanAFolder(theFile)
else
ProcessAFile(theFile)
end if
end ProcessAFileOrFolder
on ScanAFolder(theFolder)
--
-- This handler scans through a folder. The ProcessAFile hander is called for each file
-- found in the folder. Folders are handled by calling ScanFolder to recursivly
-- work through the folder tree
--
set fileNames to list folder theFolder
repeat with aFile in fileNames
set theFile to (theFolder as string) & contents of aFile
ProcessAFileOrFolder(alias theFile)
end repeat
end ScanAFolder
on open of filesList
--
-- Drag and drop handler. Pass each of the files or folders to ScanAFile which does the right
-- thing.
--
Initialize()
repeat with aFile in filesList
ProcessAFileOrFolder(contents of aFile)
end repeat
Finalize()
end open
on run
--
-- Run handler. Prompt the user for a file to process.
--
Initialize()
set theFile to choose file
ProcessAFile(theFile)
Finalize()
end run
on suffixDel(i)
set text item delimiters of me to ""
set i to i as string
if i contains "." then
set my text item delimiters to "."
set i to every text item of i
if (count of every character of (last item of i as string)) <= 4 then
set i to (items 1 thru -2 of i) as string
set my text item delimiters to ""
return i
else
set i to i as string
set text item delimiters of me to ""
return i
end if
else
return i
end if
end suffixDel
Du kannst ein neues Suffix angeben, in deinem Fall ".jpg". Sicherheitshalber werden vorher alle Suffixe entfernt und neu gesetzt (damit du immer die richtigen hast).
Die "cleanList" kann natürlich beliebig erweitert werden, z.B. für Sonderzeichen usw.:
set cleanList to {{"ü", "ue"}, {"ä", "ae"}, {"ö", "oe"}, {" ", "_"}, {"-", "_"}, {"+", "_"}, {"ü", "ue"}, {"ä", "ae"}, {"ö", "oe"}}
Einfach Script starten oder Files oder Ordner draufziehen...
Gruß
TMA
als Antwort auf: [#420676]