This repository has been archived by the owner on Feb 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
iPhotoImportTask.lua
executable file
·65 lines (49 loc) · 2.01 KB
/
iPhotoImportTask.lua
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
62
63
64
65
local LrPathUtils = import 'LrPathUtils'
local LrFileUtils = import 'LrFileUtils'
local LrDialogs = import 'LrDialogs'
local LrTasks = import 'LrTasks'
iPhotoImportTask = {}
function iPhotoImportTask.processRenderedPhotos( functionContext, exportContext )
local exportSession = exportContext.exportSession
local exportParams = exportContext.propertyTable
-- Export message settings
local nPhotos = exportSession:countRenditions()
local progressScope = exportContext:configureProgress{
title = nPhotos > 1
and LOC( '$$$/iPhotoExportService/ProgressMany=Importing ^1 photos in iPhoto', nPhotos )
or LOC '$$$/iPhotoExportService/ProgressOne=Importing one photo in iPhoto',
}
-- Export the photos
local files = {}
for i, rendition in exportContext:renditions{ stopIfCanceled = true } do
local photo = rendition.photo
local success, pathOrMessage = rendition:waitForRender()
if progressScope:isCanceled() then break end -- Check for cancellation again after photo has been rendered
if success then
table.insert( files, pathOrMessage )
end
end
local path = LrPathUtils.parent( files[1] )
-- Write Lightroom input to a session.txt file for AppleScript later on
local f = assert(io.open(path .. "/session.txt", "w+"))
f:write("export_done=false\n")
if exportParams.createAlbum == true then
f:write("album_name=" .. exportParams.album .. "\n")
end
f:close()
-- Import photos in iPhoto and wait till photos are imported by reading the session file
local importer_command = "osascript \"" .. LrPathUtils.child(_PLUGIN.path, "iPhotoImport.app") .. "\" " .. LrPathUtils.parent(files[1])
LrTasks.execute(importer_command)
local done = false
while done ~= true do
LrTasks.sleep(2)
local f = assert(io.open(path .. "/session.txt", "r"))
for line in f:lines() do
if string.find(line, 'export_done=true') then
done = true
break
end
end
f:close()
end
end