Skip to content

Instantly share code, notes, and snippets.

@arronmabrey
Created December 1, 2011 02:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arronmabrey/1413073 to your computer and use it in GitHub Desktop.
Save arronmabrey/1413073 to your computer and use it in GitHub Desktop.
middleman-transmitsync.rb
module Middleman::Features::TransmitSync
class << self
def registered(app)
app.after_build do
project_transmitsync_favorite_name = app.transmit_sync_favorite
macruby_eval = <<-macrubyEval
framework 'ScriptingBridge'
@transmit = SBApplication.applicationWithBundleIdentifier('com.panic.Transmit')
@transmitsync_favorite_name = ARGV.join('')
@transmitsync_favorite = false
@transmitsync_tab_open = false
@start_time = Time.now
def log(m)
puts 'Transmit Sync: ' + m
end
begin
@transmit.favorites.each do |fav|
if fav.name == @transmitsync_favorite_name
@transmitsync_favorite = fav
end
end
if @transmitsync_favorite
@transmit.documents.each do |doc|
doc.tabs.each do |tab|
if tab.name == @transmitsync_favorite.name
@transmitsync_tab_open = true
result = tab.localBrowser.synchronizeTo(tab.remoteBrowser,
deleteOrphanedItems:true,
compareUsingSize:true,
followSymlinks:false,
automaticallyDetermineTimeOffset:true,
withTimeOffset:0,
usingSkipRules:@transmit.skipRules,
saveReportToPath:'../transmit-sync-report'
)
if result
raise 'Finished'
else
raise 'Failed'
end
end
end
end
raise if @transmit.documents.empty? or @transmitsync_tab_open == false
else
raise 'Aborted - Could not find the transmit favorite: ' + @transmitsync_favorite_name
end
rescue Exception => e
message = e.message
if message.empty?
message = 'Aborted - For sync to work. You need to open the transmit favorite: ' + @transmitsync_favorite_name
end
log message
log 'exited in ' + (Time.now - @start_time).round(2).to_s + ' seconds.'
end
macrubyEval
puts 'Transmit Sync: Starting...'
puts `macruby -e "#{macruby_eval}" "#{project_transmitsync_favorite_name}"`
end
end
alias :included :registered
end
end
# This script is the equivalent of clicking the sync button. Make sure you set the correct remote path and local path in you're transmit favorit. I point my local path to the middleman build folder.
# Add this to your config.rb file.
configure :build do
set :transmit_sync_favorite, 'Project name.' # Transmit favorite name
activate :transmit_sync
end
# Also you need to have macruby installed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment