#!/usr/bin/env ruby # linky - easy file sharing on a local network # by Yanik Magnan - http://r-ch.net/ require 'fileutils' require 'socket' require 'tempfile' # LONG USERNAME GOES HERE LONG_USERNAME = "Yanik" # Get important constants HOME = ENV['HOME'] PUB = "#{HOME}/Public" OBJ = ARGV[0] AIM = ARGV[1] def local_ip UDPSocket.open do |s| s.connect '64.233.187.99', 1 s.addr.last end end URL = "afp://;AUTH=No%20User%20Authent@#{local_ip}/#{LONG_USERNAME}'s%20Public%20Folder" if OBJ.nil? then puts "specify an object" exit 1 else type = case when File.file?(OBJ): "F" when File.directory?(OBJ): "D" else "?" end if type == "F" then puts "* File detected." FileUtils::cp(OBJ, PUB) puts "* File now public." `echo "#{URL}" | pbcopy` puts "* URL in clipboard:" puts " #{URL}" elsif type == "D" then puts "compress directory first" end end # AIM sending here if AIM.nil? then # NOTHING else src = <<-src tell application "iChat" send ¬ "#{OBJ} => #{URL}" to buddy "AIM:#{AIM}" end tell src out = Tempfile.new("scpt") out << src out.close `cat #{out.path} | osascript` end