Created
February 22, 2016 18:23
-
-
Save kav/c986e37fecedc87f9ebc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Import Simple Note Folder into Apple Notes. | |
-- This is based on a script I found to do general note import modified to work with the simplenote web export | |
-- get a file to import to a note | |
--set noteFiles to choose folder with prompt "Import which files?" | |
set noteFiles to every item of (choose file with prompt "Choose the Files you'd like to import:" with multiple selections allowed) as list | |
-- get the name of the account that you want to add the note to | |
set accountName to getNameOfTargetAccount() | |
-- get the name of the folder to add the note to | |
set folderName to getNameOfTargetFolderOfAccount(accountName) | |
repeat with noteFile in noteFiles | |
-- get the note name from the file name | |
set {noteName, ext} to getFirstLine_andExtension(noteFile) | |
-- get the file's text as html | |
if ext is "html" then | |
set noteText to read noteFile | |
else | |
-- convert the file's contents into html code | |
set noteText to do shell script "/usr/bin/tail -n +2 " & quoted form of POSIX path of noteFile & " | /usr/bin/textutil -stdin -stdout -convert html" --| /usr/bin/tidy -ibq -utf8 --show-warnings no --force-output yes" | |
end if | |
tell application "Notes" | |
tell account accountName | |
-- make sure the folder exists | |
if not (exists folder folderName) then make new folder with properties {name:folderName} | |
-- add the note to the folder | |
tell folder folderName | |
make new note with properties {name:noteName, body:noteText} | |
end tell | |
end tell | |
end tell | |
end repeat | |
(****************** SUBROUTINES *****************) | |
-- this lets you choose which acount you want to target | |
-- if there's only 1 account then that account name is returned | |
on getNameOfTargetAccount() | |
tell application "Notes" | |
if (count of accounts) is greater than 1 then | |
set theseAccountNames to the name of every account | |
set thisAccountName to choose from list theseAccountNames with prompt "Add note to which account?" | |
if thisAccountName is false then error number -128 | |
set thisAccountName to thisAccountName as text | |
else | |
set thisAccountName to the name of first account | |
end if | |
return thisAccountName | |
end tell | |
end getNameOfTargetAccount | |
-- this lets you choose which folder you want to target from an account | |
-- if there's only 1 folder then that folder name is returned | |
on getNameOfTargetFolderOfAccount(accountName) | |
set folderName to missing value | |
tell application "Notes" | |
tell account accountName | |
if (count of folders) is greater than 1 then | |
set theseFolderNames to the name of every folder | |
set folderName to choose from list theseFolderNames with prompt "Add note to which folder?" | |
if folderName is false then error number -128 | |
set folderName to folderName as text | |
else | |
set folderName to the name of first folder | |
end if | |
end tell | |
end tell | |
return folderName | |
end getNameOfTargetFolderOfAccount | |
on getName_andExtension(f) | |
set f to f as text | |
set {name:nm, name extension:ex} to info for file f without size | |
if ex is missing value then | |
set ex to "" | |
else | |
set nm to text 1 thru ((count nm) - (count ex) - 1) of nm | |
end if | |
return {nm, ex} | |
end getName_andExtension | |
on getFirstLine_andExtension(f) | |
set f to f as text | |
set {name:nm, name extension:ex} to info for file f without size | |
set theText to read file f | |
set theList to paragraphs of theText | |
return {item 1 of theList, ex} | |
end getFirstLine_andExtension |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment