Created
November 21, 2008 18:52
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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