There are a lot of examples of converters to JPG and i am trying to change one for my needs but i need little help please. The requirements are:
- It should be an AppleScript Droplet. I am using Script Editor ( for some reason Automator can't run a simple droplet drag and drop function for me ).
- The output folder for the JPGs should not be prompted by the user .. but set as a variable in the code permanently and easly changed.
- The quality ( compression ) of the converted JPG should also have to be easly customisable in the code.
- The converted JPG files have to be converted to Color profile Adobe RGB 1998 if necessary.
I know Image Events allow us to set the JPG compression like :
save openedFile as JPEG with compression level (low|medium|high)
but unfortunately i need more customisation.
A shell script will help me to set the level from 10 to 100 but unfortunately i can't implement the shell script properly. Little help please about points 3 and 4. Thank you !
on run
display dialog "Please drag image files to this script to turn them into JPEGs"
end run
on open draggeditems
set End_Folder to "Macintosh HD:Users:zzz:Desktop:End"
repeat with currentFile in draggeditems
tell application "Image Events"
set openedFile to open (currentFile as alias)
set fileLocation to the location of openedFile
set fileName to the name of openedFile
set Path_to_Converted_File to (End_Folder & ":" & text 1 thru -5 of fileName & ".jpg")
do shell script "sips --setProperty formatOptions 10 " & openedFile
save openedFile as JPEG in Path_to_Converted_File
--save openedFile as JPEG with compression level low in Path_to_Converted_File (low|medium|high)
close openedFile
end tell
end repeat
end open
Mixing up Image Events and
sips
is more confusing than useful, and sincesips
can perform the various options you are looking for (such as 3 & 4), it makes more sense to use it for everything. Setting a few variables for the various options will let you change them as needed, or if adding preferences or whatever. Thesips
man page will give you more details about the various options; I’ve added comments for the ones used in the following script:Edited to add: The shell script is expecting POSIX paths, so the aliases passed to the
open
handler are coerced and quoted in the event they contain spaces.