O'Reilly logo

AppleScript: The Missing Manual by Adam Goldstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Picking a File from a Dialog Box

Back on Sidebar 4.2, you learned how to use the display dialog command to present information onscreen, and how to give feedback to your scripts while they're running. The trouble with that command, though, is that you can't choose a file with it. And when you're using Finder commands, you often want to choose a file for your script to work with.

That's where the choose file command comes in. Rather than having to specify an actual file name in your script, choose file uses Mac OS X's standard Open dialog box, letting you pick the precise file you want to work on (Figure 5-8). That way you can choose a different file for your script to operate on each time it runs.

When you use the choose file command, you see the same Open dialog box that you see in other Mac OS X programs. There's only one difference: the choose file dialog box shows normally hidden files (like .DS_Store), too. There are some benefits to this feature: you can see all the Unix configuration files that Mac OS X uses, for example. However, if it bothers you to have all those hidden files clogging up your Open dialog box, just add the without invisibles option to the end of your choose file command.

Figure 5-8. When you use the choose file command, you see the same Open dialog box that you see in other Mac OS X programs. There's only one difference: the choose file dialog box shows normally hidden files (like .DS_Store), too. There are some benefits to this feature: you can see all the Unix configuration files that Mac OS X uses, for example. However, if it bothers you to have all those hidden files clogging up your Open dialog box, just add the without invisibles option to the end of your choose file command.

In its purest form, the choose file command can occupy a line all by itself—displaying an Open dialog box but doing absolutely nothing else:

choose file

Of course, it won't do much ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required