Your best friend for file transfer.

Fetch application logoFetch
Fetch Icon Fetch Help > Concepts > Scripting

NOTE: Fetch 5.8 does not offer AppleScript support. The documentation below is only accurate for Fetch 5.7.7 and earlier. AppleScript support may return in a future release of Fetch.

Fetch supports a number of Apple events. This makes it possible to automate tasks in Fetch with a scripting tool such as AppleScript. It also makes it possible for other programs to use Fetch as a helper application for resolving FTP and SFTP Uniform Resource Locators (URLs). This help topic describes Fetch's support for the URL, Fetch, and Interarchy Apple event suites.

Fetch also provides a variety of Automator actions. You may find that setting up an Automator workflow to automate a Fetch task is even easier than using AppleScript. For more information, see the introduction to using Automator with Fetch and Automator actions help topics.

Fetch supports Apple event recording. The easiest way to get a feel for scripting Fetch, or to find out how to script a task, is to turn on recording in your script editor, perform the task manually, and then examine the script that has been recorded. Most user actions will be recorded as script statements. For security reasons, Fetch will not record passwords, so when you run the recorded scripts you may have to furnish passwords, unless those passwords are stored in your keychain.

It is also useful to examine Fetch's Apple event dictionary, since it provides a complete list of the supported object classes, properties, and events.

You can download a set of example AppleScripts for Fetch from the Fetch Softworks website.

If you used AppleScript with previous versions of Fetch, you should read the AppleScript changes help topic for more information about changes to Fetch's scripting terminology.

URL Suite

Fetch supports the geturl (GURL) event from the Standard URL Apple event suite, originally designed by John Norstad of Northwestern University and a group of Internet software authors. In AppleScript, the event is specified as follows:

tell application "Fetch"
geturl "ftp://ftp.fetchsoftworks.com/"
end tell

The geturl event is used by the Mac OS and other applications to pass URLs to other applications for resolution. So email programs, web browsers, and newsreaders can pass FTP and SFTP URLs to Fetch using geturl.

Fetch Suite

Fetch supports the following object classes that are specific to Fetch:

  • the application object, which can contain each of the following kinds of objects:
    • window objects
    • transfer window objects, which can contain:
      • remote item objects
      • remote file objects
      • remote folder objects
    • shortcut list window objects, which can contain:
      • shortcut objects
    • the fetch shortcuts window object, which can contain:
      • shortcut objects
    • text window objects
    • media window objects
    • the transcript window object
    • url objects

Fetch objects also have properties specific to Fetch. For example, the application object has all the preferences settings as properties, so you can refer to its download folder or text line ending style.

You can use the standard Core suite of commands to manipulate Fetch objects. The standard commands include close, count, delete, duplicate, exists, get, make, move, open, quit, save, and set. To this list Fetch adds the following commands: download, put into, send to, edit, edit new text file, get information about, mirror, refresh file list, stop, and view verbose file list.

Here are examples of some of these events, used with a variety of Fetch Apple event objects:

close text window "ftp.fetchsoftworks.com messages"
set bcount to count shortcut list window "Fetch Shortcuts" each shortcut
delete remote file "a.out" of transfer window "csvax.polytech.edu"
duplicate remote file "cool.gif" to alias "Hobbes:Desktop Folder:"
set fexists to exists shortcut "cool site" of shortcut list window "Fetch Shortcuts"
get display server messages
make new transfer window with properties {hostname:"ftp.fetchsoftworks.com", initial folder:"/example"}
move shortcut 1 of shortcut list window "Fetch Shortcuts" to shortcut list window "Best Shortcuts"
open parent folder of transfer window 1
quit
save text window "ftp.fetchsoftworks.com messages" in file "Hobbes:server messages"
set transfer mode of transfer window 1 to Binary
download url "ftp://ftp.fetchsoftworks.com/pub/mac/README"
view verbose file list transfer window "ftp.fetchsoftworks.com"
put into transfer window "ftp.fetchsoftworks.com" item alias "Hobbes:Desktop Folder:Picture 3" binary format MacBinaryIII
send to url "ftp://ftp.fetchsoftworks.com/" ftp command "LIST -lR"

Interarchy Suite

Nolobe's Interarchy, originally known as Anarchie, was the first Macintosh FTP client to support scripting via Apple events. Fetch supports a subset of the Interarchy suite of events, to make it easier to reuse scripts written for Interarchy and Anarchie (and because it is a straight-forward and functional collection of events). The supported events are:

To download a remote file:
fetch alias "My hard disk:my folder:cool file" host "ftp.example.com" user "fred" password "secret" path "remotedir/cool.file.hqx"

To upload a file:
store alias "My hard disk:my folder:file to upload" host "ftp.example.com" user "fred" password "secret" path "uploaddir/new.file"

To delete a remote file or remote folder:
remove host "ftp.example.com" user "fred" password "secret" path "remotedir/bad.file"

To view a file list:
interarchy list host "ftp.example.com" user "fred" password "secret" path "remotedir"

To create a remote folder:
mkdir host "ftp.example.com" user "fred" password "secret" path "remotedir/newdir"

To rename a remote file or remote folder:
rename host "ftp.example.com" user "fred" password "secret" path "remotedir/old.name" newname "new.name"

To edit a remote file with BBEdit (or other selected text editor):
interarchy edit host "ftp.example.com" user "fred" password "secret" path "remotedir/filttoedit.txt"

To send a raw FTP command:
sendcommand host "ftp.example.com" user "fred" password "secret" command "SITE A LIST"

The user and password parameters for any of the Interarchy Suite commands can be omitted if you are using anonymous FTP. You cannot omit the path parameter when using the forms above. Also, the host, user, password, and path parameters can be replaced by a single url parameter; for example:

fetch alias "My hard disk:my folder:cool file" url "ftp://fred:secret@ftp.example.com/remotedir/cool.file.hqx"

If you want to use SFTP instead of FTP with any of the Interarchy suite commands, append "sftp true" to the command, for example:

fetch alias "My hard disk:my folder:cool file" host "ftp.example.com" user "fred" password "secret" path "remotedir/cool.file.hqx" sftp true