CreateLowRes: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
This AppleScript automagically creates low res images from high res images in a hot folder. | 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. | 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 | Download here: upload:createlowres2009-06-30.zip | ||
<tt> | <tt> | ||
:(* CreateLowRes.scpt (c) by Heiko Kretschmer | :<nowiki>(* CreateLowRes.scpt (c) by Heiko Kretschmer *)</nowiki> | ||
:: | ::<nowiki></nowiki> | ||
:(* *************************************************************************** *) | :<nowiki>(* *************************************************************************** *)</nowiki> | ||
:(* Globals *) | :<nowiki>(* Globals *)</nowiki> | ||
:<nowiki>global gTargetDPI, gLocked, gFolderNameLowRes, gSendReturnMax, gDebugLog, gSearchFolder, gFileLogPOSIXPath, gFileSuffixesToProcess</nowiki> | :<nowiki>global gTargetDPI, gLocked, gFolderNameLowRes, gSendReturnMax, gDebugLog, gSearchFolder, gFileLogPOSIXPath, gFileSuffixesToProcess</nowiki> | ||
:<nowiki>global gTargetSuffix</nowiki> | :<nowiki>global gTargetSuffix</nowiki> | ||
:: | ::<nowiki></nowiki> | ||
:<nowiki>#, gSearchPath</nowiki> | :<nowiki>#, gSearchPath</nowiki> | ||
:# property new_foldername : "TIFF Images" | :<nowiki># property new_foldername : "TIFF Images"</nowiki> | ||
:: | ::<nowiki></nowiki> | ||
:(* *************************************************************************** *) | :<nowiki>(* *************************************************************************** *)</nowiki> | ||
:(* Functions *) | :<nowiki>(* Functions *)</nowiki> | ||
:on main(scanFolderMacOS) | :<nowiki>on main(scanFolderMacOS)</nowiki> | ||
::<nowiki>if gLocked is false then</nowiki> | ::<nowiki>if gLocked is false then</nowiki></nowiki> | ||
:::<nowiki>set gLocked to true</nowiki> | :::<nowiki>set gLocked to true</nowiki></nowiki> | ||
:::<nowiki>tell me to say ("Starting up, checking " & (POSIX path of scanFolderMacOS) as string)</nowiki> | :::<nowiki>tell me to say ("Starting up, checking " & (POSIX path of scanFolderMacOS) as string)</nowiki> | ||
: | :<nowiki></nowiki> | ||
:::(* Check this folder and its sub-folders *) | :::<nowiki>(* Check this folder and its sub-folders *)</nowiki> | ||
:::<nowiki>scanFolder(scanFolderMacOS)</nowiki> | :::<nowiki>scanFolder(scanFolderMacOS)</nowiki> | ||
: | :<nowiki></nowiki> | ||
:::<nowiki>set gLocked to false (* We're through, unlock *)</nowiki> | :::<nowiki>set gLocked to false (* We're through, unlock *)</nowiki> | ||
::else # if locked | ::<nowiki>else # if locked</nowiki> | ||
:::tell me to say ("We're locked, so I'm skipping this run.") | :::<nowiki>tell me to say ("We're locked, so I'm skipping this run.")</nowiki> | ||
::end if (* not locked *) | ::<nowiki>end if (* not locked *)</nowiki> | ||
:end main | :<nowiki>end main</nowiki> | ||
:: | ::<nowiki></nowiki> | ||
:(* create low res file, if low res does not exist, or low res is older than highres *) | :<nowiki>(* create low res file, if low res does not exist, or low res is older than highres *)</nowiki> | ||
:on createLowResOfFile(fileHighRes) | :<nowiki>on createLowResOfFile(fileHighRes)</nowiki> | ||
::: | :::<nowiki></nowiki> | ||
::(* Create LowRes-Folder *) | ::<nowiki>(* Create LowRes-Folder *)</nowiki> | ||
::set fileHighResPOSIXPath to (POSIX path of fileHighRes) | ::<nowiki>set fileHighResPOSIXPath to (POSIX path of fileHighRes)</nowiki> | ||
::tell me to say ("fileHighResPOSIXPath: " & fileHighResPOSIXPath) | ::<nowiki>tell me to say ("fileHighResPOSIXPath: " & fileHighResPOSIXPath)</nowiki> | ||
::tell me to set containingFolder to pathOfPOSIXFilepath(fileHighResPOSIXPath) & "/" | ::<nowiki>tell me to set containingFolder to pathOfPOSIXFilepath(fileHighResPOSIXPath) & "/"</nowiki> | ||
::set containingFolderAlias to POSIX file containingFolder | ::<nowiki>set containingFolderAlias to POSIX file containingFolder</nowiki> | ||
::tell me to say ("Containing folder: \"" & containingFolder & "\"") | ::<nowiki>tell me to say ("Containing folder: \"" & containingFolder & "\"")</nowiki> | ||
::tell application "Finder" | ::<nowiki>tell application "Finder"</nowiki> | ||
:::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 *) | :::<nowiki>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 *)</nowiki> | ||
::::tell me to say ("Creating low-res-folder \"" & gFolderNameLowRes & "\" in \"" & containingFolder & "\"") | ::::<nowiki>tell me to say ("Creating low-res-folder \"" & gFolderNameLowRes & "\" in \"" & containingFolder & "\"")</nowiki> | ||
::::make new folder at containingFolderAlias with properties {name:gFolderNameLowRes} (* http://www.macresearch.org/tutorial_applescript_for_scientists_part_i *) | ::::<nowiki>make new folder at containingFolderAlias with properties {name:gFolderNameLowRes} (* http://www.macresearch.org/tutorial_applescript_for_scientists_part_i *)</nowiki> | ||
:::end if | :::<nowiki>end if</nowiki> | ||
::end tell | ::<nowiki>end tell</nowiki> | ||
::tell me to set fileName to fileOfPOSIXFilepath(fileHighResPOSIXPath) | ::<nowiki>tell me to set fileName to fileOfPOSIXFilepath(fileHighResPOSIXPath)</nowiki> | ||
::tell me to set filenameWithoutSuffix to filenameWithoutSuffix(fileName) | ::<nowiki>tell me to set filenameWithoutSuffix to filenameWithoutSuffix(fileName)</nowiki> | ||
::tell me to say ("filenameWithoutSuffix: " & filenameWithoutSuffix) | ::<nowiki>tell me to say ("filenameWithoutSuffix: " & filenameWithoutSuffix)</nowiki> | ||
::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) *) | ::<nowiki>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) *)</nowiki> | ||
::tell me to say ("lowResFileNameWithoutSuffix: " & lowResFileNameWithoutSuffix) | ::<nowiki>tell me to say ("lowResFileNameWithoutSuffix: " & lowResFileNameWithoutSuffix)</nowiki> | ||
::set lowResFileName to lowResFileNameWithoutSuffix & "." & gTargetSuffix | ::<nowiki>set lowResFileName to lowResFileNameWithoutSuffix & "." & gTargetSuffix</nowiki> | ||
::tell me to say ("lowResFileName: " & lowResFileName) | ::<nowiki>tell me to say ("lowResFileName: " & lowResFileName)</nowiki> | ||
::set lowResFolderAlias to POSIX file (containingFolder & gFolderNameLowRes & "/") | ::<nowiki>set lowResFolderAlias to POSIX file (containingFolder & gFolderNameLowRes & "/")</nowiki> | ||
::tell me to say ("lowResFolderAlias: " & lowResFolderAlias) | ::<nowiki>tell me to say ("lowResFolderAlias: " & lowResFolderAlias)</nowiki> | ||
::set lowResFilePOSIXPath to (POSIX path of lowResFolderAlias) & lowResFileName | ::<nowiki>set lowResFilePOSIXPath to (POSIX path of lowResFolderAlias) & lowResFileName</nowiki> | ||
::tell me to say ("lowResFilePOSIXPath: " & lowResFilePOSIXPath) | ::<nowiki>tell me to say ("lowResFilePOSIXPath: " & lowResFilePOSIXPath)</nowiki> | ||
:::<nowiki></nowiki> | |||
:: | |||
: | |||
</ |
Revision as of 22:14, 2 July 2009
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)
- if gLocked is false then</nowiki>
-
- (* 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
- 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 *)
- 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)