- ; Drop shadow script: batch-drop-shadow.scm
- ; Michiel Roos
- (define (batch-drop-shadow pattern
- offsetx
- offsety
- radius)
- (let* ((filelist (cadr (file-glob pattern 1))))
- (while (not (null? filelist))
- (let* ((filename (car filelist))
- (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
- (drawable (car (gimp-image-get-active-layer image))))
- (script-fu-drop-shadow image drawable offsetx offsety radius '(0 0 0) 80.0 TRUE)
- (set! drawable (car (gimp-image-flatten image)))
- (file-jpeg-save RUN-NONINTERACTIVE image
- drawable
- filename
- filename
- 0.88 ;quality
- 0
- TRUE
- FALSE
- ""
- 1
- FALSE
- FALSE
- 2
- )
- (gimp-image-delete image)
- )
- (set! filelist (cdr filelist))
- )
- )
- )
Back in the day I worked for an advertising company and had a desk in the studio where all the shiny Macs lived. They had all these cool Adobe programs that could do amazing things for you when hooked to 'folder actions'. I never cared a lot about having those cool tools for myself, but now I write manuals occasionally and I wanted to have a nice folder action to add a drop shadow to screenshots.
Tuning OSX screenshots
OSX adds shadows to screenshots automagically. I don't like those since they are big as in 20px wide. So first I disabled those using the following command (typed into a terminal window):
defaults write com.apple.screencapture disable-shadow -bool true killall SystemUIServer
You can also adjust the screenshot image type and location using the 'defaults' command. Instead of 'jpg' you can use png or gif for example.
defaults write com.apple.screencapture type jpg
defaults write com.apple.screencapture location "/Users/username/Desktop/Shots"
killall SystemUIServer
Adding drop shadows using a headless Gimp
Then I used 'the Gimp' because it is cheap (as in Free Beer). The latest versions (2.6) finally handles color profiles in a decent way. You can install the latest Gimp version using MacPorts.
I used the 'drop shadow' (under Filters -> Light and Shadow). I was happy for a while . . . until I was writing the DAM manual for TYPO3. Manually adding all those drop shadows to the screenshots started to hurt. Thinking back of the days when I worked for the other employer I started to search for a way to get Gimp to add a drop shadow when dropping a screenshot file onto a folder.
The gimp can run in 'batch mode' and use 'scripts' to do anything you would normally do through a GUI. You can automate any task for which no visual pinpointing or manual path selection is needed. Here is a script in 'scheme' (the language Gimp uses for scripts) to create a drop shadow for an image and then save it as a 88% quality jpg file:
Place this script in your scripts directory. On my system this is in ~/.gimp-2.6/scripts. If you don't have that folder, create it first.
If you did this correctly, you can now call the script, feeding it an image file. The parameters are offsetx, offsety and radius (set to 8, 8 and 10 below).
/opt/local/bin/gimp --no-data -i -b '(batch-drop-shadow "Picture 1.jpg" 8 8 10)' -b '(gimp-quit 0)'
This should result in a shiny drop shadow added to the screenshot.
Creating a folder action
Now we need to tie this to a 'folder action'. If you do not have folder actions enabled, enable them using "/Applications/AppleScript/Folder Actions Setup". Place this script in the folder: "~/Library/Scripts/Folder Action Scripts".
- (*
- Image - drop shadow
- This Folder Action handler is triggered whenever items are added to the attached folder.
- The script creates a drop shadow around the image.
- Copyright © 2008 Michiel Roos
- *)
- property type_list : {"JPEG"}
- property extension_list : {"jpg", "jpeg"}
- on adding folder items to this_folder after receiving these_items
- -- PROCESS EACH OF THE ITEMS ADDED TO THE ATTACHED FOLDER
- try
- -- PROCESS THE ITEM
- process_items(this_folder)
- on error error_message number error_number
- if the error_number is not -128 then
- tell application "Finder"
- activate
- display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
- end tell
- end if
- end try
- end adding folder items to
- -- this sub-routine processes files
- on process_items(this_folder)
- -- NOTE that the variable this_item is a file reference in alias format
- try
- -- convert alias reference to string
- --set this_item to this_item as string
- with timeout of 900 seconds
- do shell script "/opt/local/bin/gimp --no-data -i -b '(batch-drop-shadow \"" & POSIX path of this_folder & "*.jpg\" 8 8 10)' -b '(gimp-quit 0)'"
- end timeout
- on error error_message
- tell application "Finder"
- activate
- display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
- end tell
- end try
- end process_items
Now you are ready to assign this script to a folder of your choice. I have a folder inside my 'Shots' folder that is called 'add drop shadow'. You can right-click the folder and choose 'More' from the context menu. There you can 'Enable folder actions' and 'Configure folder actions'.
So now you can make a bunch of screenshots and drop them of the 'drop shadow' folder. A drop shadow will automagically be added to your screenshots.
Don't forget to move the images out of the folder again. I'm sure there is room for improvement here, but this solution has saved me a lot of time.


