TweetFollow Us on Twitter

An Introduction to Scripting Transmit

Volume Number: 22 (2006)
Issue Number: 6
Column Tag: AppleScript Essentials

An Introduction to Scripting Transmit

by Benjamin S. Waldie

In last month's column, we discussed how to script Fetch (<http://www.fetchsoftworks.com>), a popular FTP/SFTP client for the Mac. In this month's column, we will continue our discussion of interacting with remote servers via FTP/SFTP. This time, we will use Transmit, another popular application among Mac users.

Like Fetch, Transmit is a commercial application. It is available for purchase from Panic, Inc. at <http://www.panic.com/transmit/>. A limited demonstration version is also available for download from the Panic website. If you do not own Transmit already, and are interested in following along with the example scripts throughout this month's column, then I would encourage you to download and install the demonstration version. All example code in this column was written and tested with Transmit version 3.5.1. If you are using a different version of Transmit, then some of the example code specified below may need to be adjusted in order to function with the version that you are using.

Connecting to a Server

The first step in interacting with a remote server is to open a new connection. For testing purposes, I enabled incoming FTP access on an iMac that resides on my local network. If you have the ability to do this on a separate local machine, then you may wish to do so. However, before you do, you'll want to make sure that your network is secure. If you do not have a separate local machine that can be used to simulate a remote machine, then you will need to gain access to a remote server.



Figure 1. A New Connection in Transmit

To open a connection to a remote server, you must first create a new document in Transmit, and then open a connection session within that document. See figure 1. The following example code demonstrates how this is done.

set theServerAddress to "10.0.1.3"
set theUserName to "myUserName"
set thePassword to "myPassword"
set theDirectory to "Documents/FTP Main/"
tell application "Transmit"
   set theDocument to make new document with properties {name:theServerAddress}
   tell theDocument
      tell current session
         connect to theServerAddress as user theUserName with password thePassword with initial path 
         theDirectory
      end tell
   end tell
end tell
--> true

You may notice that, in this example code, the connect command resulted in a value of true. Many of Transmit's commands will result in a true or false value, indicating whether or not the command was successful.

When connecting to a remote server, it is also possible to specify the type of connection that should be made, such as FTP, SFTP, WebDAV, and more. To do this, make use of the connect command's connection type parameter. For example, the following code would attempt to open an SFTP connection with the specified server, rather than a standard FTP connection.

tell application "Transmit"
   set theDocument to make new document with properties {name:theServerAddress}
   tell theDocument
      tell current session
         connect to theServerAddress as user theUserName with password thePassword with initial path 
         theDirectory with connection type SFTP
      end tell
   end tell
end tell

Notice that, in the example code above, I chose to specify a name for the newly created document, as it is created. In this case, I have chosen to use the server IP address for the name of the document. Doing this provides me with a way that I can refer to the document by name later, if I should choose to do so. I have also set a variable named theDocument to the result of the make command, which is a reference to the newly created document. This variable may also be used later in my code to refer to the document.

When a new document is created in Transmit, an initial session is automatically created, but is not connected to the server at that time. The connect command, therefore, must be used to initiate the connection to the server. In the example code above, we addressed the initially created session in the new document by referring to the current session property of the document. In Transmit, a single document can actually contain one or more connection sessions. Like Safari's ability to display multiple web pages within a single window, this is done through the use of tabs in the document's window. See figure 2.



Figure 2. Example of Transmit's Session Tabs

If you are working with a document that contains multiple session tabs, you may interact with any one that you wish, by referring to it by name or index, i.e. front to back position. For example:

tell application "Transmit"
   tell session "10.0.1.3" of document 1
      -- Do something
   end tell
end tell

To determine the name of a given session, you may access the name property of that session. The following code demonstrates how to retrieve the name of the current session.

tell application "Transmit"
   tell document 1
      name of current session
   end tell
end tell
--> "10.0.1.3"

As we have seen, a document in Transmit has a name, and just like a session, you can get that name at any time by accessing the name property of the document.

tell application "Transmit"
   name of document 1
end tell
--> "10.0.1.3"

One more thing regarding server connections. Prior to initiating a new connection, you may want to determine whether a session is already connected to a server. You can do this by accessing the is connected property of the session.

tell application "Transmit"
   tell document 1
      tell current session
         is connected
      end tell
   end tell
end tell
--> true

Working with Remote Directories

Once you have connected to a server, you are ready to begin working with remote directories on that server. To create a new folder in the current remote directory, use the create remote folder command, and specify a value for its name parameter.

tell application "Transmit"
   tell document 1
      tell current session
         create remote folder named "Job 1000"
      end tell
   end tell
end tell
--> true

In Transmit, local files and folders are known as your stuff and remote files and folders are known as their stuff. By accessing the their stuff property of a session, you can determine the path to the currently displayed remote directory.

tell application "Transmit"
   tell document 1
      tell current session
         their stuff
      end tell
   end tell
end tell
--> "/Users/bwaldie/Documents/FTP Main"

You can also retrieve a list of the names of any files and folders within the current remote directory of a specified session by making use of the list remote directory command.

tell application "Transmit"
   tell document 1
      tell current session
         list remote folder
      end tell
   end tell
end tell
--> {"Job 1000"}

To change directories on a remote server, use the set their stuff command, and specify the path of the desired directory that you would like to display. This specified path should be in relation to the currently displayed remote directory. For example, the following code would change the directory to a folder named Job 1000, within the current remote directory.

tell application "Transmit"
   tell document 1
      tell current session
         set their stuff to "Job 1000/"
      end tell
   end tell
end tell
--> true

The concepts that we have discussed so far have all dealt with remote directories. In Transmit, however, you can also manually navigate your local drive from within the same session tab that displays your remote connection. Doing so can allow you to select files and folders to upload or download, synchronize directories, and more, without ever having to leave the Transmit application. In addition to the AppleScript terminology we have discussed for interacting with remote directories, similar terminology exists for interacting with local directories. The following example code demonstrates how to change the local directory to a specified folder on your hard drive. This particular code will change the local directory to the current user's desktop folder.

tell application "Transmit"
   tell document 1
      tell current session
         set your stuff to (path to desktop folder)
      end tell
   end tell
end tell
--> true

If you are interested in interacting with local directories, then I would encourage you to explore Transmit's AppleScript dictionary for a complete listing of terminology pertaining to local directories.

Uploading Items

Uploading files or folders to a remote directory is done with the use of the upload command. When using this command, you may specify the path to an item to be uploaded, relative to the current local directory, or you may specify an AppleScript alias reference, as done in the following example code.

set thePath to choose file with prompt "Please select an item to upload:" without invisibles
tell application "Transmit"
   tell document 1
      tell current session
         upload item thePath with resume mode replace
      end tell
   end tell
end tell
--> true

When utilizing the upload command, the with resume mode optional parameter may be used to indicate what type of action to take, if a remote item with the same name already exists. In the previous example, I chose to replace existing items. Other options include prompting the user to specify what to do, resuming a partially uploaded item, or skipping the upload all together.

Downloading Items

Downloading remote items is done in a similar manner to that of uploading items. Use the download command, and specify the name or path to the item you want to download, relative to the currently displayed remote directory. Like the upload command, the download command has an optional with resume mode parameter, which may be used to specify how the download is handled if an existing item with the same name already exists in the download folder.

Also, when downloading a remote item, a download folder is not specified. The specified item will be downloaded into the currently displayed local directory for the specified session in Transmit. Remember, you can change the currently displayed local directory by using the set your stuff command.

set theOutputFolder to path to desktop folder
tell application "Transmit"
   tell document 1
      tell current session
         set your stuff to theOutputFolder
         download item "Job Image 1.png" with resume mode replace
      end tell
   end tell
end tell
--> true

Miscellaneous Tasks

We have now covered a number of tasks that you will probably want to perform in Transmit, including connecting to a remote server, creating remote folders, and uploading and downloading items. Transmit can also be used to perform a variety of other tasks, some of which we will now discuss briefly.

To delete a remote file or folder, you may use the delete remote item command, and specify the name or path, relative to the currently displayed remote directory, of the item that you want to delete.

tell application "Transmit"
   tell document 1
      tell current session
         delete remote item "Job Image 1.png"
      end tell
   end tell
end tell
--> true

If you are maintaining a lengthy server connection, then there may be times when you would like to refresh the currently displayed directory. This may be done by using the refresh command. The following example code demonstrates how to refresh the currently displayed remote directory.

tell application "Transmit"
   tell document 1
      tell current session
         refresh list their stuff files
      end tell
   end tell
end tell
--> true

We have already seen how you can determine the path to the current remote directory by accessing the their stuff property of a session. Another similar session property, their stuff selection, can be used to retrieve a list of any selected files or folders in the currently displayed remote directory. For example:

tell application "Transmit"
   tell document 1
      tell current session
         their stuff selection
      end tell
   end tell
end tell
--> {"/Users/bwaldie/Documents/FTP Main/Job 1000"}

Transmit also has the ability to synchronize a remote directory with a local directory. To do this, you will first need to change both the local and remote directories to the desired locations. Once you have done this, use the synchronize command to perform the synchronization. Optional parameters for this command will allow you to specify the type and behavior of the synchronization that will occur. For example, the following code will perform a mirrored synchronization uploading new or modified local items to the remote directory.

tell application "Transmit"
   tell document 1
      tell current session
         synchronize direction upload files method mirror
      end tell
   end tell
end tell
--> true

    NOTE: Something that was not discussed in last month's column is that Fetch also possesses the ability to perform a local/remote folder synchronization. This is done using the mirror command, as demonstrated below.

    set theLocalFolder to alias ((path to desktop folder as string) & "Job 1000:")
    set theRemoteFolder to "Documents/FTP Main/Job 1000/"
    tell application "Fetch"
       tell transfer window 1
          mirror theLocalFolder to remote folder theRemoteFolder
       end tell
    end tell

To prevent errors from being displayed during AppleScript processing, you may set the value of the SuppressAppleScriptAlerts property of the Transmit application to true.

tell application "Transmit"
   set SuppressAppleScriptAlerts to true
end tell

Once you have completed any desired tasks in Transmit, you may wish to disconnect from the remote server. To do this, make use of the disconnect command. For example:

tell application "Transmit"
   tell document 1
      tell current session
         disconnect
      end tell
   end tell
end tell

You also have the option to close a document instead, which would sever any server connections in any opened sessions.

tell application "Transmit"
   tell document 1
      close
   end tell
end tell

In Closing

Hopefully, this column and last month's column should give you a good side-by-side comparison of two popular scriptable FTP/SFTP applications. Fetch's AppleScript support does provide access to some additional functionality, which is not currently accessible through scripting of Transmit. However, regardless, both applications are very user- friendly, and have great AppleScript support that is fairly straightforward, and should be relatively easy to learn. Personally, I enjoy scripting and using them both.

If you are interested in scripting Transmit, be sure to explore its AppleScript dictionary in detail, as there are a number of features that we did not discuss in this column. You may also want to download the example AppleScript files that Panic provides to get users started with scripting Transmit. A link to these example scripts can be found on the Transmit support page of the Panic website at <http://www.panic.com/transmit/support.html>.

Until next time, keep scripting!


Ben Waldie is the author of the best selling books "AppleScripting the Finder" and the "Mac OS X Technology Guide to Automator", available from <http://www.spiderworks.com>. Ben is also president of Automated Workflows, LLC, a company specializing in AppleScript and workflow automation consulting. For years, Ben has developed professional AppleScript-based solutions for businesses including Adobe, Apple, NASA, PC World, and TV Guide. For more information about Ben, please visit <http://www.automatedworkflows.com>, or email Ben at <ben@automatedworkflows.com>.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Minecraft 1.20.2 - Popular sandbox build...
Minecraft allows players to build constructions out of textured cubes in a 3D procedurally generated world. Other activities in the game include exploration, gathering resources, crafting, and combat... Read more
HoudahSpot 6.4.1 - Advanced file-search...
HoudahSpot is a versatile desktop search tool. Use HoudahSpot to locate hard-to-find files and keep frequently used files within reach. HoudahSpot is a productivity tool. It is the hub where all the... Read more
coconutBattery 3.9.14 - Displays info ab...
With coconutBattery you're always aware of your current battery health. It shows you live information about your battery such as how often it was charged and how is the current maximum capacity in... Read more
Keynote 13.2 - Apple's presentation...
Easily create gorgeous presentations with the all-new Keynote, featuring powerful yet easy-to-use tools and dazzling effects that will make you a very hard act to follow. The Theme Chooser lets you... Read more
Apple Pages 13.2 - Apple's word pro...
Apple Pages is a powerful word processor that gives you everything you need to create documents that look beautiful. And read beautifully. It lets you work seamlessly between Mac and iOS devices, and... Read more
Numbers 13.2 - Apple's spreadsheet...
With Apple Numbers, sophisticated spreadsheets are just the start. The whole sheet is your canvas. Just add dramatic interactive charts, tables, and images that paint a revealing picture of your data... Read more
Ableton Live 11.3.11 - Record music usin...
Ableton Live lets you create and record music on your Mac. Use digital instruments, pre-recorded sounds, and sampled loops to arrange, produce, and perform your music like never before. Ableton Live... Read more
Affinity Photo 2.2.0 - Digital editing f...
Affinity Photo - redefines the boundaries for professional photo editing software for the Mac. With a meticulous focus on workflow it offers sophisticated tools for enhancing, editing and retouching... Read more
SpamSieve 3.0 - Robust spam filter for m...
SpamSieve is a robust spam filter for major email clients that uses powerful Bayesian spam filtering. SpamSieve understands what your spam looks like in order to block it all, but also learns what... Read more
WhatsApp 2.2338.12 - Desktop client for...
WhatsApp is the desktop client for WhatsApp Messenger, a cross-platform mobile messaging app which allows you to exchange messages without having to pay for SMS. WhatsApp Messenger is available for... Read more

Latest Forum Discussions

See All

‘Resident Evil 4’ Remake Pre-Orders Are...
Over the weekend, Capcom revealed the Japanese price points for both upcoming iOS and iPadOS ports of Resident Evil Village and Resident Evil 4 Remake , in addition to confirming the release date for Resident Evil Village. Since then, pre-orders... | Read more »
Square Enix commemorates one of its grea...
One of the most criminally underused properties in the Square Enix roster is undoubtedly Parasite Eve, a fantastic fusion of Resident Evil and Final Fantasy that deserved far more than two PlayStation One Games and a PSP follow-up. Now, however,... | Read more »
Resident Evil Village for iPhone 15 Pro...
During its TGS 2023 stream, Capcom showcased the Following upcoming ports revealed during the Apple iPhone 15 event. Capcom also announced pricing for the mobile (and macOS in the case of the former) ports of Resident Evil 4 Remake and Resident Evil... | Read more »
The iPhone 15 Episode – The TouchArcade...
After a 3 week hiatus The TouchArcade Show returns with another action-packed episode! Well, maybe not so much “action-packed" as it is “packed with talk about the iPhone 15 Pro". Eli, being in a time zone 3 hours ahead of me, as well as being smart... | Read more »
TouchArcade Game of the Week: ‘DERE Veng...
Developer Appsir Games have been putting out genre-defying titles on mobile (and other platforms) for a number of years now, and this week marks the release of their magnum opus DERE Vengeance which has been many years in the making. In fact, if the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for September 22nd, 2023. I’ve had a good night’s sleep, and though my body aches down to the last bit of sinew and meat, I’m at least thinking straight again. We’ve got a lot to look at... | Read more »
TGS 2023: Level-5 Celebrates 25 Years Wi...
Back when I first started covering the Tokyo Game Show for TouchArcade, prolific RPG producer Level-5 could always be counted on for a fairly big booth with a blend of mobile and console games on offer. At recent shows, the company’s presence has... | Read more »
TGS 2023: ‘Final Fantasy’ & ‘Dragon...
Square Enix usually has one of the bigger, more attention-grabbing booths at the Tokyo Game Show, and this year was no different in that sense. The line-ups to play pretty much anything there were among the lengthiest of the show, and there were... | Read more »
Valve Says To Not Expect a Faster Steam...
With the big 20% off discount for the Steam Deck available to celebrate Steam’s 20th anniversary, Valve had a good presence at TGS 2023 with interviews and more. | Read more »
‘Honkai Impact 3rd Part 2’ Revealed at T...
At TGS 2023, HoYoverse had a big presence with new trailers for the usual suspects, but I didn’t expect a big announcement for Honkai Impact 3rd (Free). | Read more »

Price Scanner via MacPrices.net

New low price: 13″ M2 MacBook Pro for $1049,...
Amazon has the Space Gray 13″ MacBook Pro with an Apple M2 CPU and 256GB of storage in stock and on sale today for $250 off MSRP. Their price is the lowest we’ve seen for this configuration from any... Read more
Apple AirPods 2 with USB-C now in stock and o...
Amazon has Apple’s 2023 AirPods Pro with USB-C now in stock and on sale for $199.99 including free shipping. Their price is $50 off MSRP, and it’s currently the lowest price available for new AirPods... Read more
New low prices: Apple’s 15″ M2 MacBook Airs w...
Amazon has 15″ MacBook Airs with M2 CPUs and 512GB of storage in stock and on sale for $1249 shipped. That’s $250 off Apple’s MSRP, and it’s the lowest price available for these M2-powered MacBook... Read more
New low price: Clearance 16″ Apple MacBook Pr...
B&H Photo has clearance 16″ M1 Max MacBook Pros, 10-core CPU/32-core GPU/1TB SSD/Space Gray or Silver, in stock today for $2399 including free 1-2 day delivery to most US addresses. Their price... Read more
Switch to Red Pocket Mobile and get a new iPh...
Red Pocket Mobile has new Apple iPhone 15 and 15 Pro models on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide service using all the major... Read more
Apple continues to offer a $350 discount on 2...
Apple has Studio Display models available in their Certified Refurbished store for up to $350 off MSRP. Each display comes with Apple’s one-year warranty, with new glass and a case, and ships free.... Read more
Apple’s 16-inch MacBook Pros with M2 Pro CPUs...
Amazon is offering a $250 discount on new Apple 16-inch M2 Pro MacBook Pros for a limited time. Their prices are currently the lowest available for these models from any Apple retailer: – 16″ MacBook... Read more
Closeout Sale: Apple Watch Ultra with Green A...
Adorama haș the Apple Watch Ultra with a Green Alpine Loop on clearance sale for $699 including free shipping. Their price is $100 off original MSRP, and it’s the lowest price we’ve seen for an Apple... Read more
Use this promo code at Verizon to take $150 o...
Verizon is offering a $150 discount on cellular-capable Apple Watch Series 9 and Ultra 2 models for a limited time. Use code WATCH150 at checkout to take advantage of this offer. The fine print: “Up... Read more
New low price: Apple’s 10th generation iPads...
B&H Photo has the 10th generation 64GB WiFi iPad (Blue and Silver colors) in stock and on sale for $379 for a limited time. B&H’s price is $70 off Apple’s MSRP, and it’s the lowest price... Read more

Jobs Board

Housekeeper, *Apple* Valley Villa - Cassia...
Apple Valley Villa, part of a 4-star senior living community, is hiring entry-level Full-Time Housekeepers to join our team! We will train you for this position and Read more
Housekeeper, *Apple* Valley Village - Cassi...
Apple Valley Village Health Care Center, a 4-star rated senior care campus, is hiring a Part-Time Housekeeper to join our team! We will train you for this position! Read more
Optometrist- *Apple* Valley, CA- Target Opt...
Optometrist- Apple Valley, CA- Target Optical Date: Sep 23, 2023 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 796045 At Target Read more
Senior *Apple* iOS CNO Developer (Onsite) -...
…Offense and Defense Experts (CODEX) is in need of smart, motivated and self-driven Apple iOS CNO Developers to join our team to solve real-time cyber challenges. Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.