By Matt Neuburg
Cover | Table of Contents | Colophon
image01.jpg, and press Return again. Now you
select the next image file with mouse, and do it again. The business
of doing it again rapidly becomes tiresome and error-prone. You have
to remember where you are ("What was the number I
assigned to the previous image file I renamed?"),
think what to do next ("What do I get when I add 1
to the previous number?"), and do it (click, Return,
type, Return). It isn't long before
you're making mistakes clicking or typing, or your
eyes are starting to go out of focus, or you are just plain bored out
of your skull.on open folderList
repeat with aFolder in folderList
tell application "Finder"
if kind of aFolder is "Folder" then
my renameStuffIn(aFolder)
end if
end tell
end repeat
end open
on renameStuffIn(theFolder)
set ix to 0
tell application "Finder"
set folderName to name of theFolder
set allNames to name of every item of theFolder
repeat with aName in allNames
set thisItem to item aName of theFolder
set ix to ix + 1
set newName to folderName & (ix as string)
try
set name of thisItem to newName
end try
end repeat
end tell
end renameStuffIn
try
do shell script ¬
"bless -folder9 'Volumes/main/System Folder' -setOF" ¬
password "myPassword" with administrator privileges
tell application "System Events" to restart
end try
<Body> tags. So this BBEdit
script post-processes my XML output, removing the line breaks between
<Body> tags just before I send an article
off to the magazine:tell application "BBEdit"
activate
repeat
find "<Body>([\\s\\S]*?)</Body>" ¬
searching in text 1 of text window 1 ¬
options {search mode:grep, starting at top:false,
wrap around:false, reverse:false, case sensitive:false, ¬
match words:false, extend selection:false} ¬
with selecting match
if not found of the result then
exit repeat
end if
remove line breaks selection of text window 1
end repeat
end tell#!/usr/bin/ruby
class Histogram
def initialize
@tally = Hash.new(0)
end
def analyze(s)
s.split.each do |word|
myword = word.downcase.gsub(/[^a-z0-9]/, "")
@tally[myword] = @tally[myword] + 1 if !myword.empty?
end
@tally.sort { |x,y| y[1]<=>x[1] }
end
end
analysis = Histogram.new.analyze(File.new(ARGV[0]).read)
analysis.
But what to do with this data? It was decided that the most flexible
approach would be to store it in an
Excel worksheet for later
retrieval, manipulation, and analysis. So the Ruby script now goes on
to hand the data over to Excel, using AppleScript.
Here's the second part of the same Ruby script:MacScript
function, which accepts a string and
compiles and runs it as AppleScript on the fly. For more about using
VBA in Word, see Steven Roman's Writing
Word Macros (O'Reilly).Chr(13). The calls to this
function must be concatenated with the rest of your string to form
the AppleScript code. Quotation marks are also a cause of concern and
possible confusion.http://www.apple.com/applescript/folder_actions/.)on adding folder items to ff after receiving L
tell application "Finder"
repeat with f in L
set n to the name of f
if n ends with ".hqx" then
tell application "StuffIt Expander" to expand f
end if
end repeat
end tell
tell application "System Events"
if process "StuffIt Expander" exists then
tell application "StuffIt Expander" to quit
end if
end tell
end adding folder items tohttp://www.apple.com/applescript/toolbar/.osascript
. This verb is your key to leaping the
gulf between Unix and AppleScript. You should read the relevant
manpages. (Further details are provided in Chapter 23.)osascript can execute a compiled script file or
can compile and execute a
string. The option
-e signals that it's a string,
not a script file, and of course if you're going to
type a literal string, this raises all the usual problems of escaped
characters. In the Terminal you can usually bypass these problems by
single-quoting the string.-ss flag. I generally prefer this
because it does a better job of showing you what sort of reply
you've really got. The curly braces and the double
quotes show clearly that it's a list of strings:$ osascript -e 'tell app "Finder" to get name of every disk' xxx, main, second, extra $ osascript -ss -e 'tell app "Finder" to get name of every disk' {"xxx", "main", "second", "extra"}
osascript. The difficulties are
even worse than in the Microsoft Word example earlier in this
chapter, because two environments, Perl and the shell, are going to
munge this string before it gets to AppleScript. This line of Perl
shows what I mean:$s = `osascript -e "tell app \\"Finder\\" to get name of every disk"`;
|
Fig. No.
|
Filename
|
Caption (or description)
|
|---|---|---|
|
1-1
|
wfi_0101.eps
|
Overview of the Windows NT operating system environment.
|
|
1-2
|
wfi_0102.eps
|
Name space presented by the Object Manager.
|
|
1-3
|
wfi_0103.eps
|
Filter drivers in the driver hierarchy.
|
table class in the FrameMaker dictionary. But
then, to make the reference to an illustration file, I choose the
Import File menu item, and it is not at all clear to me what kind of
entity I generate as a result.get, set, and
count; even select is fairly
standard. The only unusual verb I ended up using was
http://www.ecma-international.org/publications/standards/ECMA-262.htm):A scripting language is a programming language that is used to manipulate, customise, and automate the facilities of an existing system. In such systems, useful functionality is already available through a user interface, and the scripting language is a mechanism for exposing that functionality to program control. In this way, the existing system is said to provide a host environment of objects and facilities, which completes the capabilities of the scripting language.
TEXT' on Mac OS 9 and earlier. The Script Editor
saves such a file with both features, and it can be opened on both
platforms.APPL' and creator 'aplt'. The
Mac OS X Script Editor saves the applet with both features. There is
also a new "application bundle"
format, also with file extension .app, which is
not backward-compatible with systems prior to Mac OS X 10.3
("Panther").open handler for dealing with the drop. Indeed,
the very same script application can operate both as an applet (it
does something when it is opened by launching) and as a droplet (it
does something when files or folders are dragged-and-dropped onto its
icon). A droplet has a different creator type from an applet
('dplt'), and it has a different icon, which looks
like an applet's icon with the addition of a
downward arrow. The Script Editor makes this distinction when you
save the file, based on the presence or absence of an
open handler.osax'. On Mac OS X it can also be a bundle with
extension .osax. A scripting addition is often
referred to as an
osax (plural osaxen).
On Mac OS 9, osaxen live in the System Folder, in its Scripting
Additions subfolder. On Mac OS X the supplied osaxen live in
/System/Library/ScriptingAdditions; the user may
add osaxen to /Library/ScriptingAdditions or to
~/Library/ScriptingAdditions, according to the
domain of their desired availability.