Advertisements

Blog Archives

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"

  activate

  if theSite = "ASUsersList" then
   search the web for "site:http://lists.apple.com/archives/applescript-users " & searchTerm
  else
   search the web for "site:http://macscripter.net " & 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.


Advertisements

how to stop help windows always being on top

HelpViewer
Ever called up a HelpViewer window in an app only to find that you have to close the window in order to get back to the app and start following the instructions? That can be highly annoying if the instructions aren’t easy to remember.

That’s because the HelpViewer.app is by default set to always be on top. If you want to change that, here’s a nice little Terminal trick that will let you manage HelpViewer windows just like a normal window, courtesy of new tipster site defaults-write.com. Here’s what you do:

1. If you have any HelpViewer windows open, close them first.

2. Open Terminal.app (/Applications/Utilities/Terminal.app) and paste this command into the window:

defaults write com.apple.helpviewer DevMode -bool true

and press ‘return’ on your keyboard.

That’s it! From now on, you’ll be able to switch focus between the app and the HelpViewer window so that you can work with whichever one you need on top.

Tip: If you want to reverse the behaviour, use the same command as above but replace ‘true’ at the end with ‘false’.

If you like exploring the various things you can do with defaults preferences, have a rummage around the defaults-write.com site, a nice little addition to our bookmarks list! 🙂

%d bloggers like this: