Coding

Yes, female coders do exist…

Friday, August 15th, 2008 | Coding, Random | 3 Comments

Capt. Jennifer Guarnieri is a test engineer with the integrated test and evaluation of the Space Vehicle Directorate, Air Force Research Laboratory, Kirtland, Air Force Base.…and they use Emacs.

Tags: , , ,

Resize Images Using AppleScript

Monday, August 11th, 2008 | Apple, Coding, Tips & Tricks | No Comments

The Mac Tricks and Tips website had a great tip on how to quickly resize multiple images on your Mac using an AppleScript:

Open the Script Editor application (a quick way to do this is by searching for it with Spotlight), then copy the following code into the editor:

-- save in Script Editor as an Application, then
-- drag image files onto the Application's icon
 
on open some_items
  repeat with this_item in some_items
    try
      rescale_and_save(this_item)
    end try
  end repeat
end open
 
to rescale_and_save(this_item)
  tell application "Image Events"
    launch
  set the target_width to 120
 
  -- open the image file
  set this_image to open this_item
 
  set typ to file type of this_image
 
  copy dimensions of this_image to {current_width, current_height}
  if current_width is greater than current_height then
    scale this_image to size target_width
  else
    -- figure out new height
    -- y2 = (y1 * x2) / x1
    set the new_height to (current_height * target_width) / current_width
    scale this_image to size new_height
  end if
 
  tell application "Finder" to set new_item to (container of this_item
      as string) & "scaled." & (name of this_item)
    save this_image in new_item as typ
  end tell
end rescale_and_save

If you want to change the size the output image will have, you need to change this line:

set the target_width to 120

Click the “Compile” button on the toolbar and wait until the purple text color is replaced by blue and green (this indicates that the code compiled without any errors).

AppleScript Editor - Resize Images

AppleScript Editor - Resize Image

Click the File menu and choose Save, then save the script as a script file so you have a copy of the source code. Click the File menu again, choose Save As, and save the script as an Application (you could create a differently named Application from this script for each change you make to the target_width variable in the source code).

To run your new application simply drop an image file on it to have a resized copy of the image created in the folder the application is stored in.

Tags: , , , , ,

Categories

Search

Meta

Afrigator