Skip the navigation

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

May 21, 2009 12:01 AM ET

The good news here is that you can get some decent support for regular expressions by installing a free add-on from Satimage or, for smaller amounts of text, dumping it into an app like TextWrangler, which has such support. AppleScript can also incorporate more powerful commands from Perl, Ruby, Unix or anything else that can be accessed via a shell script, and then assign the results to a variable. For more on that, check out Apple's technical note called "do shell script in AppleScript."

Despite its drawbacks -- and what language doesn't have any? -- I've found AppleScript to be a great tool for parsing drudgework out of my workday.

And now, without further ado, here's a sampling of cool AppleScripts out there that just might make you love your Mac even more.

Search for any term in your clipboard on Computerworld or elsewhere

This is one of my faves: Take any term you've copied into your clipboard (command-C), regardless of the app you're in, and Safari displays search results on that term from

To use:

  1. Copy the code.
  2. Open your script editor (you'll find it in your Applications/AppleScript folder).
  3. Paste the code into the larger top portion of your script editor.
  4. Save the file as a script in your Library/Scripts folder. (Note: If you open the AppleScript utility in the Applications/AppleScript folder, you can have your script menu display in the top menu bar.)


#This script searches for the contents of text in the clipboard.

set url1 to ""
set url2 to "&x=0&y=0&cof=FORID%3A9#1214"

tell application "System Events"
        set myquery to the clipboard
        end tell

-- changes space to plus using function at end of file

set thequery to SaR(myquery, " ", "+")

tell application "Safari"
        tell application "System Events"
                tell process "Safari"
                        click menu item "New Tab" of menu "File" of menu bar 1

                end tell
        end tell
        set theURL to url1 & thequery & url2
        set URL of document 1 to theURL
end tell

-- handler (function) for search and replace
-- (posted by James Nierodzik at
on SaR(sourceText, findText, replaceText)
        set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, findText}
        set tempText to text items of sourceText
        set AppleScript's text item delimiters to replaceText
        set sourceText to tempText as string
        set AppleScript's text item delimiters to atid
        return sourceText
end SaR

If you want scripts that will search for terms in your clipboard at other sites, MacScripter has AppleScript versions posted for searching highlighted text on Google and Wikipedia (within Safari only). Download and install in your Scripts folder.

Our Commenting Policies