Description
In response to this thread on the Evernote forum, I hashed out this script! It creates a duplicate copy of a selected note (or notes), including tags, and prepends "Copy Of" to the title, a.k.a., "How the Mac Finder's Command-D Function Works". Set this script up with a keyboard shortcut and you should be all set!The Code
(*
http://veritrope.com
Evernote -- Make Duplicate Copies of Notes
Version 1.0
April 22, 2011
Project Status, Latest Updates, and Comments Collected at:
http://veritrope.com/code/evernote-make-duplicate-copies-of-notes
*)
(*
======================================
// MAIN PROGRAM
=======================================
*)
--TEMP FILES PROCESSED ON THE DESKTOP
set ExportFolder to ((path to desktop folder) & "Temp Export From Evernote:") as string
set SaveLoc to (my f_exists(ExportFolder))
set theFile to SaveLoc & "test.enex"
--GET THE NOTE INFORMATION
tell application "Evernote"
set the_notes to selection
set noteNotebook to (notebook of item 1 of the_notes)
--EXPORT THE NOTES
export the_notes to file theFile
--MAKE THE DUPLICATE (IMPORT)
set theItems to import theFile ¬
to noteNotebook with tags
--GIVE DUPLICATE A DISTINCT NAME
repeat with theItem in theItems
set noteName to title of item 1 of theItem
set title of item 1 of theItem to "Copy of " & noteName
end repeat
end tell
--DELETE TEMP FOLDER
my trashfolder(SaveLoc)
(*
======================================
// HANDLER SUBROUTINES
=======================================
*)
--FOLDER EXISTS
on f_exists(ExportFolder)
try
set myPath to (path to home folder)
get ExportFolder as alias
set SaveLoc to ExportFolder
on error
tell application "Finder" to set SaveLoc to (make new folder with properties {name:"Temp Export From Evernote"}) as alias
set SaveLoc to (SaveLoc as text)
end try
end f_exists
--SILENT DELETE OF TEMP FOLDER (THANKS MARTIN MICHEL!)
on trashfolder(SaveLoc)
try
set trashfolderpath to ((path to trash) as Unicode text)
set srcfolderinfo to info for (SaveLoc as alias)
set srcfoldername to name of srcfolderinfo
set SaveLoc to (SaveLoc as alias)
set SaveLoc to (quoted form of POSIX path of SaveLoc)
set counter to 0
repeat
if counter is equal to 0 then
set destfolderpath to trashfolderpath & srcfoldername & ":"
else
set destfolderpath to trashfolderpath & srcfoldername & " " & counter & ":"
end if
try
set destfolderalias to destfolderpath as alias
on error
exit repeat
end try
set counter to counter + 1
end repeat
set destfolderpath to quoted form of POSIX path of destfolderpath
set command to "ditto " & SaveLoc & space & destfolderpath
do shell script command
-- this won't be executed if the ditto command errors
set command to "rm -r " & SaveLoc
do shell script command
return true
on error
return false
end try
end trashfolder
http://veritrope.com
Evernote -- Make Duplicate Copies of Notes
Version 1.0
April 22, 2011
Project Status, Latest Updates, and Comments Collected at:
http://veritrope.com/code/evernote-make-duplicate-copies-of-notes
*)
(*
======================================
// MAIN PROGRAM
=======================================
*)
--TEMP FILES PROCESSED ON THE DESKTOP
set ExportFolder to ((path to desktop folder) & "Temp Export From Evernote:") as string
set SaveLoc to (my f_exists(ExportFolder))
set theFile to SaveLoc & "test.enex"
--GET THE NOTE INFORMATION
tell application "Evernote"
set the_notes to selection
set noteNotebook to (notebook of item 1 of the_notes)
--EXPORT THE NOTES
export the_notes to file theFile
--MAKE THE DUPLICATE (IMPORT)
set theItems to import theFile ¬
to noteNotebook with tags
--GIVE DUPLICATE A DISTINCT NAME
repeat with theItem in theItems
set noteName to title of item 1 of theItem
set title of item 1 of theItem to "Copy of " & noteName
end repeat
end tell
--DELETE TEMP FOLDER
my trashfolder(SaveLoc)
(*
======================================
// HANDLER SUBROUTINES
=======================================
*)
--FOLDER EXISTS
on f_exists(ExportFolder)
try
set myPath to (path to home folder)
get ExportFolder as alias
set SaveLoc to ExportFolder
on error
tell application "Finder" to set SaveLoc to (make new folder with properties {name:"Temp Export From Evernote"}) as alias
set SaveLoc to (SaveLoc as text)
end try
end f_exists
--SILENT DELETE OF TEMP FOLDER (THANKS MARTIN MICHEL!)
on trashfolder(SaveLoc)
try
set trashfolderpath to ((path to trash) as Unicode text)
set srcfolderinfo to info for (SaveLoc as alias)
set srcfoldername to name of srcfolderinfo
set SaveLoc to (SaveLoc as alias)
set SaveLoc to (quoted form of POSIX path of SaveLoc)
set counter to 0
repeat
if counter is equal to 0 then
set destfolderpath to trashfolderpath & srcfoldername & ":"
else
set destfolderpath to trashfolderpath & srcfoldername & " " & counter & ":"
end if
try
set destfolderalias to destfolderpath as alias
on error
exit repeat
end try
set counter to counter + 1
end repeat
set destfolderpath to quoted form of POSIX path of destfolderpath
set command to "ditto " & SaveLoc & space & destfolderpath
do shell script command
-- this won't be executed if the ditto command errors
set command to "rm -r " & SaveLoc
do shell script command
return true
on error
return false
end try
end trashfolder