05.01.2013 Views

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

406<br />

CHAPTER 23 MAC <strong>OS</strong> X AUTOMATION WITH AUTOMATOR AND APPLESCRIPT<br />

Using Actions<br />

Let’s use our keyword to do a Google image search. There are lots of actions for working with<br />

web data, but there’s no action to turn our keyword into a URL. However, there is a Run Shell<br />

Script action, and you can easily create a URL string in a shell script.<br />

To add an action to your workflow, drag it from the sidebar’s right column. When it is over<br />

the workflow area, the action will expand into a full panel. To rearrange actions within the<br />

workflow, simply drag them around.<br />

From the Utilities group, drag the Run Shell Script action to the workflow. The Ask for Text<br />

action automatically connects to the Run Shell Script action. When a workflow runs, it executes<br />

each action sequentially, from top to bottom. If an action generates output, it’s assumed to be the<br />

next action’s input. This relationship is represented by the connection between the two actions.<br />

If two actions do not connect, no data will flow between them. If you want an action to<br />

ignore the data coming from the action above it, select Ignore Input from the receiving action’s<br />

context menu.<br />

Select “/bin/bash” from the Shell drop-down and “as arguments” from the “Pass input”<br />

drop-down. Enter the following simple shell script in the text area:<br />

echo "http://images.google.com/images?q="$1<br />

This simple script will return the beginning of a Google image query URL (as determined<br />

experimentally in Safari), plus the first argument, which will be the output of the Ask for Text<br />

action: the user’s keyword input. Running the workflow will produce the completed URL, as<br />

shown in Figure 23-6.<br />

Figure 23-6. Running a shell script in Automator<br />

NOTE Shell scripting is covered in Chapter 19. Apple also provides a shell scripting primer,<br />

available online: http://developer.apple.com/documentation/OpenSource/Conceptual/<br />

ShellScripting/.<br />

Once we have the URL to the search, we’ll want to get the results. A Google image search<br />

will return a page of links. To extract the links from the page, drag the Get Link URLs from<br />

Webpages action from the Internet group. You might as well check the “Only return URLs in the<br />

same domain as the starting page” option.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!