LoginSignup
9
9

More than 5 years have passed since last update.

テキストファイル(txt,rtf)をドラッグ&ドロップでEvernoteにインポートしてくれる上、ノートの作成日と更新日をファイルから取ってくれるAppleScript

Posted at
  • Evernoteにテキストファイルをインポートしようと思ってドラッグ&ドロップしても、内容を登録してくれるのではなく添付ファイルになってしまう
  • Evernote Importer: TXT OR RTF FILES というのを見つけた (via ceron.jp)
  • しかしこれはノートの作成日&更新日が今現在になってしまう。インポートするファイルそのものの作成日と更新日を使ってほしい。

というわけで、Evernote Importer: TXT OR RTF FILESを、Finderでのファイル作成日・更新日を反映させるように改造。

  • creationDate,modificationDateが絡んでいるのがnaoya_t改変行。
main.scpt
(*
http://veritrope.com
Evernote Importer: TXT OR RTF FILE 
Version 1.03
May 26, 2010

Project Status, Latest Updates, and Comments Collected at:
http://veritrope.com/tips/evernote-importer-txt-or-rtf-files

Installation: Just double-click on the script!

FastScripts Installation (Optional, but recommended): 
--Download and Install FastScripts from http://www.red-sweater.com/fastscripts/index.html
--Copy script or an Alias to ~/Library/Scripts/Applications/Evernote
--Set up your keyboard shortcut

CHANGELOG:
1.03    TEMPORARY REMOVAL OF RTF/TXT VALIDATOR WHILE REWORKING CODE
1.02     BUG FIXES (UNDERLINING, GROWL APP)
1.01    ADDITIONAL TUNING
1.00    INITIAL RELEASE
*)property isRunning : "false"property theNum : "0"(* CHECK FOR GROWL *)if appIsRunning("GrowlHelperApp") then  set isRunning to true   tell application "GrowlHelperApp"       set allNotificationsList to {"Success Notification", "Failure Notification"}        set enabledNotificationsList to {"Success Notification", "Failure Notification"}        register as application ¬          "Import to Evernote" all notifications allNotificationsList ¬          default notifications enabledNotificationsList ¬           icon of application "Evernote"  end tellend if(*MAIN PROGRAM *)tell application "Finder"    try     --set exportedFiles to (choose file with prompt "Choose RTF or TXT Files (Multiple Selections Allowed)" of type {"RTF", "TXT"} with multiple selections allowed)        set exportedFiles to (choose file with prompt "Choose RTF or TXT Files (Multiple Selections Allowed)" with multiple selections allowed)                     repeat with exportedFile in exportedFiles           set thefileName to the name of exportedFile         set creationDate to the creation date of exportedFile           set modificationDate to the modification date of exportedFile           set filePOSIX to quoted form of (POSIX path of exportedFile)            set preHTML to (do shell script "textutil  -convert html -stdout " & filePOSIX & "")            set firstScrub to my replaceString(preHTML, "<br>", "")         set secondScrub to my replaceString(firstScrub, "<p class=\"p1\">", "")         set thirdScrub to my replaceString(secondScrub, "<p class=\"p2\">", "")         set fourthScrub to my replaceString(thirdScrub, "<p class=\"p3\">", "")         set fifthScrub to my replaceString(fourthScrub, "<p class=\"p4\">", "")         set sixthScrub to my replaceString(fifthScrub, "<p class=\"p5\">", "")          set seventhScrub to my replaceString(sixthScrub, "<span class=\"s1\">", "<u>")          set eighthScrub to my replaceString(seventhScrub, "</span>", "</u>")            set theHTML to my replaceString(eighthScrub, "</p>", "<br>")            tell application "Evernote"             set importedNote to ¬                  (create note with html theHTML ¬                       title thefileName ¬                        notebook ¬                     "My Notebook" tags ¬                       "AutoImported" created creationDate)                set modification date of importedNote to modificationDate               set theNum to theNum + 1            end tell        end repeat      (*NOTIFICATIONS*)       if isRunning is true then           my GrowlNotify(theNum)      end if      set theNum to 0     (* ERROR HANDLING *)    on error errText number errNum      if isRunning is true then           if errNum is -128 then              tell application "GrowlHelperApp" -- GROWL FAILURE FOR ERROR                    notify with name ¬                     "Failure Notification" title ¬                     "User Cancelled" description ¬                     "Failed to export!" application name "Import to Evernote"               end tell            else                tell application "GrowlHelperApp" -- GROWL FAILURE FOR ERROR                    notify with name ¬                     "Failure Notification" title ¬                     "Import Failure" description "Failed to export the item due to the following error:  " & errNum & " (" & errText & ¬                       ")" application name "Import to Evernote"               end tell            end if      else if isRunning is false then -- NON-GROWL ERROR MSG. FOR ERROR           display dialog "Item Failed to Import: " & errNum & return & errText with icon 0        end if  end tryend tell(* SUBROUTINES *)--APP DETECTon appIsRunning(appName)    tell application "System Events" to (name of processes) contains appNameend appIsRunning--GROWLon GrowlNotify(theNum)   tell application "GrowlHelperApp" -- GROWL SUCCESS      set Plural_Test to (theNum) as number       if Plural_Test is greater than 1 then           notify with name ¬             "Success Notification" title ¬             "Import Success" description "Successfully exported " & theNum & ¬             " items to the default notebook in Evernote" application name ¬                "Import to Evernote"                    else if Plural_Test is equal to 1 then          notify with name ¬             "Success Notification" title ¬             "Import Success" description "Successfully exported " & theNum & ¬             " item to the default notebook in Evernote" application name ¬             "Import to Evernote"        end if  end tellend GrowlNotify--REPLACE SUBROUTINEon replaceString(theString, theOriginalString, theNewString) set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, theOriginalString} set theStringParts to text items of theString   if (count of theStringParts) is greater than 1 then     set theString to text item 1 of theStringParts as string        repeat with eachPart in items 2 thru -1 of theStringParts           set theString to theString & theNewString & eachPart as string      end repeat  end if  set AppleScript's text item delimiters to od    return theStringend replaceString```
9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9