gist: 4016 Download_button fork
public
Public Clone URL: git://gist.github.com/4016.git
linky.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/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

Owner

Sakurina

Revisions