Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/ruby
require 'rubygems'
require 'net/ssh'
require 'net/scp'
thingsPath = "HOME/Library/Application\ Support/Cultured\ Code/Things/Database.xml"
getTimestamp = "ls -lT '#{thingsPath}' | cut -f9-13 -d' '"
getThings = "ps waux | grep [T]hings"
quitThings = "osascript -e 'tell application \"Things\"\nquit\nend tell'"
openThings = "open -a Things"
Net::SSH.start("YOUR-REMOTE-HOST.ORG", "USERNAME") do |ssh|
home = ssh.exec!("echo $HOME").chomp
remotePath = thingsPath.gsub(/HOME/, home)
remoteGetTimestamp = getTimestamp.gsub(/HOME/, home)
remoteTimestamp = DateTime.parse(ssh.exec!(remoteGetTimestamp))
home = ENV["HOME"]
localPath = thingsPath.gsub(/HOME/, home)
localGetTimestamp = getTimestamp.gsub(/HOME/, home)
localTimestamp = DateTime.parse(`#{localGetTimestamp}`)
if remoteTimestamp > localTimestamp
puts "Remote host has more recent Things database."
if `#{getThings}` != ""
puts "Quitting local Things."
system(quitThings)
end
ssh.scp.download!(remotePath.gsub(/ /, "\\ "), localPath)
puts "Received file."
puts "Re-opening local Things."
system(openThings)
else
puts "Remote host has out of date Things database"
if not ssh.exec!(getThings).nil?
puts "Quitting remote Things."
ssh.exec!(quitThings)
end
ssh.scp.upload!(localPath, remotePath.gsub(/ /, "\\ "))
puts "Transmitted file."
puts "Re-opening remote Things."
ssh.exec!(openThings)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.