Skip to content

Instantly share code, notes, and snippets.

@Timothee
Created March 26, 2023 15:07
Show Gist options
  • Save Timothee/734293d9e1250752f2116127cfcff079 to your computer and use it in GitHub Desktop.
Save Timothee/734293d9e1250752f2116127cfcff079 to your computer and use it in GitHub Desktop.
AppleScript to send Kindle clippings file to Readwise
on adding folder items to this_folder after receiving added_items
-- Because we run from `/Volumes` we need to check if it was the Kindle
-- that was just added
set kindle to false
repeat with added_item in added_items
tell application "Finder"
set item_name to name of added_item
if item_name is "Kindle" then
set kindle to true
end if
end tell
end repeat
-- early return
if not kindle then
return
end if
set attachmentPath to "/Volumes/Kindle/documents/My Clippings.txt"
set theAttachment to POSIX file attachmentPath
tell application "Finder"
if not (theAttachment exists) then
return
end if
end tell
set recipientName to "Readwise"
set recipientAddress to "add@readwise.io"
set subjectLine to "Kindle import"
set mailBody to ""
set AppleScript's text item delimiters to {"\\n"}
set mailBody to text items of mailBody
set AppleScript's text item delimiters to {"
"}
set mailBody to mailBody as text
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:subjectLine, content:mailBody, visible:false}
tell newMessage
make new to recipient with properties {name:recipientName, address:recipientAddress}
make new attachment with properties {file name:theAttachment} at after the last paragraph
send
end tell
quit
end tell
display notification "Clippings sent!" with title "Readwise" subtitle "Clippings sent!"
end adding folder items to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment