Skip to content

Instantly share code, notes, and snippets.

@henrik
Created November 21, 2008 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrik/27558 to your computer and use it in GitHub Desktop.
Save henrik/27558 to your computer and use it in GitHub Desktop.
Fix missing/incorrect image file extension on download. See http://henrik.nyh.se/2008/11/extension-action for details.
on adding folder items to myFolder after receiving myFiles
repeat with myFile in myFiles
set myPath to (POSIX path of myFile)
set myType to do shell script "file --mime-type -br " & (quoted form of myPath)
if myType is "image/jpeg" and myPath does not end with ".jpg" and myPath does not end with ".jpeg" then
set newExtension to ".jpg"
else if myType is "image/gif" and myPath does not end with ".gif" then
set newExtension to ".gif"
else if myType is "image/png" and myPath does not end with ".png" then
set newExtension to ".png"
else
set newExtension to null
end if
tell application "Finder"
if newExtension is not null then
set name of myFile to (name of myFile) & newExtension
end if
end tell
end repeat
end adding folder items to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment