By Matt Neuburg
Book Price: $39.99 USD
£28.50 GBP
PDF Price: $31.99
Cover | Table of Contents
image01.jpg, and press Return again; then you select the next image file with mouse, and do it again, and so forth. The trouble is that you don't
on open folderList
repeat with aFolder in folderList
if kind of (info for aFolder) is "Folder" then
renameStuffIn(aFolder)
end if
end repeat
end open
on renameStuffIn(theFolder)
set ix to 0
tell application "Finder"
set folderName to name of theFolder
set allItems to (get every item of theFolder)
repeat with thisItem in allItems
set ix to ix + 1
set newName to folderName & ix
set name of thisItem to newName
end repeat
end tell
end renameStuffIn
folderList tells us what was dropped onto the droplet. We process each dropped item, starting with a sanity check to make sure it's really a folder. If it is, we give each item in the folder a new name based on the folder's name along with a number that increases each time.http URL, my default browser should open and fetch that page. If it's an email address, my email program should create a new message to that addressee. In some applications you can just click a URL and the right thing happens, but many applications provide no such facility, so I have to resolve the URL manually. This means I must look at the URL and decide on the appropriate helper program; then I select and copy the URL; then I somehow start up the helper program; finally, I paste the URL into the appropriate location. In a browser, I must hit Return afterwards, in order to go to that URL; in an email program, I must create a new message first, in order to have something to paste into. This doesn't sound like very many steps, but it's all very annoying, especially in comparison to those applications where the right thing just happens with a single click.
set theProc to (get path to frontmost
application as Unicode text)
tell application "Finder"
activate
delay 1 -- give time for clip to convert from Classic
set theURL to (get the clipboard as string)
end tell
ignoring application responses
try
open location theURL
end try
end ignoring
activate application theProc
set i to 1
tell application "iTunes"
tell (get view of browser window 1)
repeat with aTrack in (get every track)
set track number of aTrack to i
set i to i + 1
end repeat
end tell
end tell
osascript command. osascript can execute a compiled script file or can compile and execute a string (indicated by the -e switch).osascript and a return character, then typing the text, and finally signalling the end of the text with Control-D. There isn't much likelihood you'd want to do this, but at least it proves that osascript is working, and the code looks exactly like normal AppleScript:
% osascript -ss
tell app "Finder"
get name of every disk
end tell
^D
{"feathers", "gromit", "Network"}
-ss flag causes the result to appear in the familiar way that AppleScript usually formats a list of strings.)
#!/usr/bin/perl
$s = <<DONE;
tell app "Finder"
get name of every disk
end
DONE
print `osascript -e '$s'`;
do shell script command).applescript
URL protocol. The href attribute of the link's <a> tag must begin like this:applescript://com.apple.scripteditor?
applescript URLs cannot be made to target any other script editor application by changing this value.applescript URLs can be made to target a desired application (or applet) by means of a preference set by the user at system level. Apple provides no interface for setting this preference; but the freeware RCDefaultApp
preference pane is an excellent way to do it (http://www.rubicode.com/Software/RCDefaultApp/ ).action=new& action=insert& action=append&
script=theCode
%20, a quote must be encoded as %22, and a return character must be encoded as %0D. At http://www.apple.com/applescript/scripteditor/12.html, Apple provides a utility script that URL-encodes text that has been copied to the clipboard, and embeds it in an 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.
A scripting language is intended for use by both professional and nonprofessional programmers. To accommodate nonprofessional programmers, some aspects of the language may be somewhat less strict.
'osas'; the extension is .scpt. Historically, this is the oldest form. Script Editor will not create a file in this form (though Script Debugger can), but if Script Editor encounters such a file it can open, edit, and save it in the same form.'TEXT'.open handler. If it does, the application becomes a droplet
. A droplet is just like an applet, except that it has a different creator type (the creator type for an applet is 'aplt', while for a droplet it's 'dplt') and a slightly different icon; functionally, the difference is that a droplet does something when file or folder icons are dropped onto its icon in the Finder. Typically, a droplet responds to the dropped items by processing them in some way (for an example, see "Calculation and Repetition" in Chapter 1). A droplet can also function like an applet: as a droplet, it does something when items are dropped onto its icon, while as an applet, it does something when it is launched from the Finder.