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
|
# File 'lib/icloud_photo/sync.rb', line 20
def upload!
tmpfile = nil
uploader = nil
script = SCRIPT.dup
script.gsub!("/Users/dashboard/screenshots", File.expand_path(@directory))
marker = 'tell me to refreshCloud("dashboard", {"sampletv"})'
index = script.index(marker) + 1
script.gsub!(marker, '')
@targets.each do |tuple|
icloud_name, image_names = tuple
files = image_names.collect{ |name| "\"#{name}\"" }
val = "\ttell me to refreshCloud(\"#{icloud_name}\", {#{files.join(", ")}})\n"
script.insert(index, val)
end
tmpfile = Tempfile.new('applescript')
tmpfile.write(script)
tmpfile.close
uploader = Tempfile.new('uploader')
uploader.close
puts "osacompile -o #{uploader.path} #{tmpfile.path}"
puts `osacompile -o #{uploader.path} #{tmpfile.path}`
puts "osascript #{uploader.path}"
puts `osascript #{uploader.path}`
ensure
tmpfile.unlink if tmpfile
uploader.unlink if uploader
end
|