CreateLowRes

From Wurst-Wasser.net
Revision as of 22:14, 2 July 2009 by Heiko (talk | contribs)
Jump to navigation Jump to search

This AppleScript automagically creates low res images from high res images in a hot folder.

Please don't complain about formatting - it's hard enough to make this look good in UseMod Wiki.

Download here: upload:createlowres2009-06-30.zip

(* CreateLowRes.scpt (c) by Heiko Kretschmer *)
(* *************************************************************************** *)
(* Globals *)
global gTargetDPI, gLocked, gFolderNameLowRes, gSendReturnMax, gDebugLog, gSearchFolder, gFileLogPOSIXPath, gFileSuffixesToProcess
global gTargetSuffix
#, gSearchPath
# property new_foldername : "TIFF Images"
(* *************************************************************************** *)
(* Functions *)
on main(scanFolderMacOS)
if gLocked is false then</nowiki>
set gLocked to true</nowiki>
tell me to say ("Starting up, checking " & (POSIX path of scanFolderMacOS) as string)
(* Check this folder and its sub-folders *)
scanFolder(scanFolderMacOS)
set gLocked to false (* We're through, unlock *)
else # if locked
tell me to say ("We're locked, so I'm skipping this run.")
end if (* not locked *)
end main
(* create low res file, if low res does not exist, or low res is older than highres *)
on createLowResOfFile(fileHighRes)
(* Create LowRes-Folder *)
set fileHighResPOSIXPath to (POSIX path of fileHighRes)
tell me to say ("fileHighResPOSIXPath: " & fileHighResPOSIXPath)
tell me to set containingFolder to pathOfPOSIXFilepath(fileHighResPOSIXPath) & "/"
set containingFolderAlias to POSIX file containingFolder
tell me to say ("Containing folder: \"" & containingFolder & "\"")
tell application "Finder"
if not (the folder gFolderNameLowRes of folder containingFolderAlias exists) then (* http://applescript.codefetch.com/example/k5/Applescript%20Examples%20CD(converted)/Chapter%205/Page%2090%20-%20Creating%20a%20Folder%20(Only%20if%20Necessary).scpt.txt?qy=if *)
tell me to say ("Creating low-res-folder \"" & gFolderNameLowRes & "\" in \"" & containingFolder & "\"")
make new folder at containingFolderAlias with properties {name:gFolderNameLowRes} (* http://www.macresearch.org/tutorial_applescript_for_scientists_part_i *)
end if
end tell
tell me to set fileName to fileOfPOSIXFilepath(fileHighResPOSIXPath)
tell me to set filenameWithoutSuffix to filenameWithoutSuffix(fileName)
tell me to say ("filenameWithoutSuffix: " & filenameWithoutSuffix)
set lowResFileNameWithoutSuffix to filenameWithoutSuffix (* In our case, the filename of the low-res-image is the same as the original file (except for the suffix) *)
tell me to say ("lowResFileNameWithoutSuffix: " & lowResFileNameWithoutSuffix)
set lowResFileName to lowResFileNameWithoutSuffix & "." & gTargetSuffix
tell me to say ("lowResFileName: " & lowResFileName)
set lowResFolderAlias to POSIX file (containingFolder & gFolderNameLowRes & "/")
tell me to say ("lowResFolderAlias: " & lowResFolderAlias)
set lowResFilePOSIXPath to (POSIX path of lowResFolderAlias) & lowResFileName
tell me to say ("lowResFilePOSIXPath: " & lowResFilePOSIXPath)