Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This applescript can be used to automatically draw on microscopic images in Adobe Photoshop as a new layer. This hasn't been tested in several years, but it depended on tiffutil to read the voxel-width from the tiff header in Leica confocal microscope files. TODO: Update and combine with the loci_tools.jar from OME project to make this more flex…
--Wednesday, May 4, 2005 6:27 PM
--Select and open the image in the frontmost Finder window in Photoshop from which the Voxel-Width data can be obtained before proceeding performing the scale bar calculation. Must use Photoshop CS or Photoshop 7.0. Must change instances of "Photoshop CS" to "Photoshop 7.0" in this script and vice versa depending on which version you are using.
tell application "Finder"
set this_file to ((the selection) as alias)
set newPath to quoted form of POSIX path of this_file
end tell
tell application "Adobe Photoshop CS6"
open this_file showing dialogs never
end try
end tell
set temp1 to display dialog "Enter desired scale bar length in µm" default answer "50"
set scalelength to text returned of temp1
--must have the unix command "tiffutil" at the localhost path of /usr/bin/ to perform this simple calculation.
set voxel_string to do shell script "/usr/bin/tiffutil -info " & newPath & " | grep Voxel-Width"
set voxel_width to last word of voxel_string
set barwidth to scalelength / voxel_width
tell application "Adobe Photoshop CS6"
-- Selections bounds are always expressed
-- in pixels, so a conversion of the document's width and height values is needed if the
-- default ruler units is other than pixels. The statements below would
-- work consistently regardless of the current ruler unit setting.
set x2 to barwidth + 412
set layerName to scalelength & "µm"
set layerName to layerName as text
set docRef to current document
set artLayerRef to make new art layer in layer set 1 of docRef
set name of artLayerRef to layerName
select current document region {{412, 489}, {x2, 489}, {x2, 497}, {412, 497}}
fill selection of current document with contents {class:RGB color, red:255, green:255, blue:255}
deselect current document
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.