Class: ICloudPhoto::Sync
- Inherits:
-
Object
- Object
- ICloudPhoto::Sync
- Defined in:
- lib/icloud_photo/sync.rb
Constant Summary collapse
- SCRIPT =
File.read(File.("../../applescript/sync.applescript", __FILE__), encoding: "UTF-8")
Instance Method Summary collapse
- #add(icloud_name, image_names) ⇒ Object
-
#initialize(directory) ⇒ Sync
constructor
A new instance of Sync.
- #upload! ⇒ Object
Constructor Details
#initialize(directory) ⇒ Sync
Returns a new instance of Sync.
10 11 12 13 |
# File 'lib/icloud_photo/sync.rb', line 10 def initialize(directory) @directory = directory @targets = [] end |
Instance Method Details
#add(icloud_name, image_names) ⇒ Object
15 16 17 18 |
# File 'lib/icloud_photo/sync.rb', line 15 def add(icloud_name, image_names) image_names = [image_names].flatten @targets << [icloud_name, image_names] end |
#upload! ⇒ Object
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.(@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 |