Loading sFTP logins into Transmit with Alfred workflow

If you manage lots of WordPress websites, dealing with sFTP logins can be a pain. Most sFTP clients don’t allow backup/restore passwords between computers. At some point I got tired of manually entering credentials and created the following Alfred workflow to automatically import from the following format.

myawesomesite.com
Address: myawesomesite.wpengine.com
Username: myawesomesite
Password: 8dni238cnj83
Protocol: sftp
Port: 2222

Alfred workflow allows for complex desktop automation

Alfred is a productivity app for the Mac. With Alfred Workflows you can automate all sorts of repetitive tasks. Now, I’m no Alfred expert! In fact, this was my first Alfred script so I’m sure it’s rough but it gets the job done.

Screen Shot 2017-03-08 at 10.20.09 PM.png

With the following Alfred workflow you can copy the above sFTP credentials and press a custom shortcut (command + option +A) which will robotically open up Transmit and fill in all of the details. Here is an example of what that looks like in practice.

ARVE Error: Aspect ratio 1.753:1 is not valid
Alfred Workflow - Bookmark sFTP into Transmit
Alfred Workflow - Bookmark sFTP into Transmit

Most of the Alfred Workflow is opening things, pressing things and pasting things. All of the hard work happens in the custom PHP script which loops through the copied lines of text and puts them into useable variables for Alfred. Here is a look at that script.

<?php

$query = $argv[1];

$results = explode("\n", $query);
$website = trim($results[0]);
$address = trim(str_replace("Address: ", "", $results[1]));
$username = trim(str_replace("Username: ", "", $results[2]));
$password = trim(str_replace("Password: ", "", $results[3]));
$protocol = trim(str_replace("Protocol: ", "", $results[4]));
$port = trim(str_replace("Port: ", "", $results[5]));

echo '{
 "alfredworkflow" : {
   "arg" : "{query}",
     "config" : {
   },
   "variables" : {
     "website": "'.$website.'",
     "address": "'.$address.'",
     "username": "'.$username.'",
     "password": "'.$password.'",
     "protocol": "'.$protocol.'",
     "port": "'.$port.'"
   }
 }
}'
?>

If you’d like to try out the workflow yourself, download Bookmark sFTP into Transmit.alfredworkflow.zip.