Skip to content

Instantly share code, notes, and snippets.

@tobiasstrebitzer
Created January 31, 2011 15:33
Show Gist options
  • Save tobiasstrebitzer/804196 to your computer and use it in GitHub Desktop.
Save tobiasstrebitzer/804196 to your computer and use it in GitHub Desktop.
This Applescript lets you select from your Transmit v4 SFTP Favourites and opens Transmit, Textmate and a (ssh- connecting) Terminal.
tell application "Finder"
set homeFolder to (path to home folder as text)
set cleanupAtStartupFolder to homeFolder & "Library:Caches:Cleanup At Startup:" as alias
if not (exists folder "Transmit" of cleanupAtStartupFolder) then
make new folder at cleanupAtStartupFolder with properties {name:"Transmit"}
end if
end tell
set transmitPath to homeFolder & "Library:Caches:Metadata:Transmit:" as alias
set transmitCachePath to homeFolder & "Library:Caches:Cleanup At Startup:Transmit:" as alias
set availableWorkspaces to {}
set availableWorkspaceFiles to {}
tell application "Finder"
set transmitFiles to name of every file of transmitPath
end tell
repeat with transmitFileName in transmitFiles
tell application "System Events"
# Open Transmit File
set transmitFile to property list file (POSIX path of ((item transmitFileName of transmitPath) as alias))
end tell
# Check for Protocol
set protocol to getProperty("com_panic_transmit_protocol", transmitFile)
if protocol is equal to "SFTP" then
set nickname to getProperty("com_panic_transmit_nickname", transmitFile)
copy nickname to the end of availableWorkspaces
copy transmitFile to the end of availableWorkspaceFiles
end if
end repeat
# Choose Workspace
set nickname to {choose from list bubbleSort(availableWorkspaces)}
set selectedWorkspaceIndex to IndexOfItem(nickname, availableWorkspaces)
set selectedWorkspaceFile to item selectedWorkspaceIndex in availableWorkspaceFiles
# Get Workspace Data
set server to getProperty("com_panic_transmit_server", selectedWorkspaceFile)
set ssh_port to getProperty("com_panic_transmit_port", selectedWorkspaceFile)
set username to getProperty("com_panic_transmit_username", selectedWorkspaceFile)
set remotePath to getProperty("com_panic_transmit_remotePath", selectedWorkspaceFile)
# Open Transmit
tell application "Transmit"
activate
set myFave to item 1 of (favorites whose name is nickname)
tell document 1
set current tab to (make new tab at end)
tell current tab
connect to myFave
end tell
end tell
end tell
# Open SSH Console
tell application "Terminal"
if username is not "" and server is not "" then
if ssh_port is not false then
set scriptString to "ssh -p " & ssh_port & " " & username & "@" & server
else
set scriptString to "ssh " & username & "@" & server
end if
set currentTab to do script scriptString
end if
end tell
# Open Textmate
do shell script "open -a TextMate \"" & (POSIX path of transmitCachePath) & "\""
on IndexOfItem(theItem, theList)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set theList to {"", theList, ""} as string
set AppleScript's text item delimiters to {"", theItem, ""} as string
set i to (count paragraphs of text item 1 of theList) mod (count paragraphs of theList)
set AppleScript's text item delimiters to astid
return i
end IndexOfItem
on getProperty(propertyName, plistFile)
tell application "System Events"
if property list item propertyName of plistFile exists then
return value of property list item propertyName of plistFile
else
return false
end if
end tell
end getProperty
on bubbleSort(theList)
script bs
property alist : theList
end script
set theCount to length of bs's alist
if theCount < 2 then return bs's alist
repeat with indexA from theCount to 1 by -1
repeat with indexB from 1 to indexA - 1
if item indexB of bs's alist > item (indexB + 1) of bs's alist then
set temp to item indexB of bs's alist
set item indexB of bs's alist to item (indexB + 1) of bs's alist
set item (indexB + 1) of bs's alist to temp
end if
end repeat
end repeat
return bs's alist
end bubbleSort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment