Skip to content

Instantly share code, notes, and snippets.

@cimm
Created November 11, 2011 22:44
Show Gist options
  • Save cimm/1359553 to your computer and use it in GitHub Desktop.
Save cimm/1359553 to your computer and use it in GitHub Desktop.
Imports a folder in iPhoto
-- debugging
on log_event(themessage)
set theLine to (do shell script "date +'%Y-%m-%d %H:%M:%S'" as string) & " " & themessage
do shell script "echo " & theLine & " >> ~/Library/Logs/AppleScript-events.log"
end log_event
-- Extract the album name from the session file
on extractAlbumName(sessionContents)
set albumName to ""
set allLines to every paragraph of sessionContents
repeat with aLine in allLines
set equalSignOffset to (offset of "=" in aLine)
if equalSignOffset > 0 then
set var to text 1 thru (equalSignOffset - 1) of aLine
if var = "album_name" then
set albumName to text ((offset of "=" in aLine) + 1) thru -1 of aLine
end if
end if
end repeat
return albumName
end extractAlbumName
-- Import exported photos in a new iPhoto album if needed
on import(sourceFolder, albumName)
tell application "iPhoto"
if albumName is equal to "" then
import from sourceFolder
else
import from sourceFolder to new album name albumName
end if
repeat while (importing)
delay 0.5
end repeat
end tell
end import
-- Update status flag in session file to tell Lightroom we are finished here
on updateSessionFile(sessionFile)
open for access sessionFile with write permission
set eof of sessionFile to 0
write "album_name=
export_done=true" to sessionFile
close access sessionFile
end updateSessionFile
-- Run the import script
on run argv
-- Read the directory from the input and define the session file
set tempFolder to item 1 of argv
set sessionFile to tempFolder & "/session.txt"
-- Scan the session file for an album name
open for access sessionFile
set sessionContents to (read sessionFile)
close access sessionFile
set albumName to extractAlbumName(sessionContents)
import(tempFolder, albumName)
updateSessionFile(sessionFile)
end run
@jbpros
Copy link

jbpros commented Nov 11, 2011

awful indentation! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment