Skip the navigation

10 AppleScripts to make you love your Mac (even more)

May 21, 2009 12:01 AM ET

Check your IP address

A simple IP utility from ScriptBuilders (accessible from the Scriptbuilders site) lets you quickly check your external IP address and copy it to your clipboard for tasks such as setting up a VPN or supporting a remote access connection.

Add lyrics to iTunes

There are hundreds of iTunes AppleScripts out there on sites such as Doug's AppleScripts for iTunes. For example, you can make tracks "bookmarkable" so they resume playing wherever they left off or pick items on an iPod so they're copied into an iTunes folder.

One of the more amusing is a script that automatically searches a database on the Web and adds a text version of a song's lyrics into iTunes. Not all songs work properly, but when a match is found, you get to see full lyrics downloaded into iTunes.

iTunes volume fade-in and fade-out

For audiophiles who prefer that their music fade in when starting up and fade out when a tune is paused or restarted manually in mid-play, O'Reilly's MacDevCenter site offers several iTunes scripts that do just that, either with or without dialog boxes.

Quick image manipulation

I'd wager that a fair number of AppleScript users would be surprised to learn that they don't need an app like Photoshop in order to script things like rotating or resizing an image.

The following script from the book Apple Training Series: AppleScript 1-2-3 resizes an image to 50% of the original.

Code

set this_file to choose file without invisibles
try
 tell application "Image Events"
 -- start the Image Events application
 launch
 -- open the image file
 set this_image to open this_file
 -- perform action
 scale this_image by factor 0.5
 -- save the changes
 save this_image with icon
 -- purge the open image data
 close this_image
 end tell
on error error_message
 display dialog error_message
end try

Of course, Photoshop gives you much more control over how images are sized, so this isn't a great technique to size images for printing or publication. However, for a quick e-mail attachment, it should be fine. There are also versions on the same Web page to size for maximum width or height, with user input setting the parameters.

Code

set this_file to choose file without invisibles
set the target_length to 640
repeat
 display dialog "Enter the target length " & "and choose the dimension of the " & "image to scale to the target length:" default answer target_length buttons {"Cancel", "Height", "Width"}
 copy the result as list to {target_length, target_dimension}
 try
  set the target_length to the target_length as number
  if the target_length is greater than 0 then
   exit repeat
  else
   error
  end if
 on error
  beep
 end try
end repeat
try
 tell application "Image Events"
  -- start the Image Events application
  launch
  -- open the image file
  set this_image to open this_file
  -- get dimensions of the image
  copy dimensions of this_image to {W, H}
  -- determine scale length
  if the target_dimension is "Height" then
   if W is less than H then
    set the scale_length to the target_length
   else
    set the scale_length to (W * target_length) / H
    set the scale_length to
 round scale_length rounding as taught in school
   end if
  else -- target dimension is Width
   if W is less than H then
    set the scale_length to (H * target_length) / W
    set the scale_length to
 round scale_length rounding as taught in school
   else
    set the scale_length to the target_length
   end if
  end if
  -- perform action
  scale this_image to size scale_length
  -- save the changes
  save this_image with icon
  -- purge the open image data
  close this_image
 end tell
on error error_message
 display dialog error_message
end try



Our Commenting Policies