how to use AppleScript to help you use AppleScript!

AppleScript search tool

Learning AppleScript can be frustrating. You need a good book, lots of patience, and core documentation like the AppleScript Language Guide and the annual release notes, but most of all you’re going to need access to instant advice. It’s in this last respect that we’re going to build a helpful little AppleScript tool to help us solve AppleScript problems.

The two best places to get help from are Apple’s AppleScript mail list and MacScripter. So, basically, we’re going to combine a couple of tools that you’ve already got (or can get for free) on your mac into a single keystroke-activated, dedicated search engine. When finished, we’ll be able to do something as simple as pressing cmd-ctl-S, type in a short search term like “display dialog” and get specific results for AppleScript.

Our tool basically relies on that fact that in Google you can do site specific searches by using the site: keyword. We’ll then add a couple of AppleScript-specific choices and use a free tool, Red Sweater’s FastScripts, to allow us to assign an easy shortcut (you could assign the keyboard shortcut without FastScripts using Mac’s Services menu, but FastScripts is a great tool you should have anyway if you’re using AppleScript, so now’s a good time to go get it!).

To get started, let’s open Script Editor and start a new script. Our script is really short, and not very complicated, here it is:

set theChoices to display dialog "Search for what?" default answer "" with title "AppleScript Search" buttons {"Cancel", "ASUsersList", "MacScripter"} default button "MacScripter"

set searchTerm to the text returned of the theChoices
set theSite to button returned of theChoices
tell application "Safari"


  if theSite = "ASUsersList" then
   search the web for "site: " & searchTerm
   search the web for "site: " & searchTerm
  end if
end tell

Run the script now, and try a couple of searches. I’ve plugged in MacScripter and ASUsers List, you might like to play with a “choose from list” and add stackOverflow, OS X Technologies or any other sites you know of. Not sure how to do that? OK, try searching for “choose from list” with your new tool, and you’ll soon find out how!

Once you’re finished with the script, use FastScripts or Services to create a shortcut. Now, the next time you’re working in Script Editor and get stuck writing a script or keep stalling over some persistent error message, just hit your shortcut and type in an appropriate search term.

Fast and simple! Automation, that’s what it’s all about!

Addendum: If you’re feeling very ambitious and want to combine several sites into one set of search results, Google allows you to set up your own personal search engine for free.

About philastokes

Freelance Writer, Developer and Technical Communicator. Explaining the unexplainable with images, video and text. Scripting anything imaginable in Applescript, Bash, C, Objective C, Cocoa, Python and Xcode.

Posted on April 28, 2015, in AppleScript and tagged , , , . Bookmark the permalink. Comments Off on how to use AppleScript to help you use AppleScript!.

Comments are closed.

%d bloggers like this: