Data retrieval from MacNote3 and migration to Write

About MacNote3

I used to use an app called ** MacNote3 ** as a notebook app that can be managed hierarchically on a Mac.

MacNote3 → http://nsek.net/SYW/software/japanese/macnote3/index.html

Another reason I loved this app was that it had a (manual) sync feature with the ** mmNote ** app available on iOS devices that allowed me to share notes between my Mac and iPhone. mmNote → http://nsek.net/SYW/software/iPhoneJ/mmnote/index.html

However, at some point mmNote stopped working with the iOS update, and I was looking for an alternative app, using it only on the Mac.

The function I wanted

It was simple, but I couldn't find anything that could be managed hierarchically. (I thought Microsoft OneNote would be good, but I didn't get used to the notes and sections.)

Encounter with Write

At that time, I happened to have a friend introduce me to an app called ** Write **. Write → http://writeapp.net/ Write allows you to manage your notes in multiple layers, and you can use the integration between Mac and iOS devices by synchronizing with iCloud or DropBox.

What's even more exciting is that it supports ** MarkDown notation **, and the iPhone's soft keyboard has been devised so that you can easily enter useful symbols for MarkDown. ** Note app for MarkDown **. It also supports MarkDown's preview function, HTML format conversion output, and PDF output. It's amazing.

It's a paid app, but I thought it wasn't expensive, so I decided to purchase all three (Mac, iPhone, and iPad versions separately) and make a full-scale transition.

Data retrieval from MacNote 3

Now, in order to migrate, you need to take out about 400 (?) Notes you currently have from MacNote3.

Fortunately, I didn't use rich text, and I didn't paste images, so I just had to extract the text.

At first, I wanted to retrieve it directly from the data folder used by MacNote3, but the data saved for each note is in XML format (?), And the text part is in a code-converted format such as BASE64. So I couldn't do it simply. MacNote 3 also has the ability to export notes, but it was a hassle to do it manually for each note.

I was about to give up, but I remembered that MacNote3 was compatible with AppleScript, and when I looked at the glossary of MacNote3 in the script editor, there were classes and methods that could be used, so there was trial and error, but the result I was able to retrieve the text of all notes at once with a simple script.

A script that retrieves the text of all note data from MacNote3

I created a script that takes out the title and body of a note, adds each delimiter line, and outputs it to one text file. If you can, you can do it with such a small number of lines.

ManNote3export.scpt


tell application "MacNote3"
	set titleList to ""
	set saveFile to choose file name
	open for access saveFile with write permission
	set allPages to all pages
	repeat with aPage in allPages
		set pTitle to title of aPage
		set pText to text of aPage
		write "== MacNote title ==" & return to saveFile
		write pTitle & return to saveFile
		write "== MacNote text ==" & return to saveFile
		write pText & return to saveFile
		write "== MacNote end ==" & return to saveFile
		set titleList to titleList & pTitle & return
	end repeat
	close access saveFile
	display dialog "The export is finished."
	set the clipboard to titleList
end tell

Data migration to Write

Since the character code of the text data extracted by AppleScript is SHIFT-JIS, convert it to UTF-8 with a text editor that can convert the character code. (When I converted it on the command line with iconv, I got an error because the internal data was wrong, so I converted it easily with Jedit X)

In the data of MacNote3, the folder (separation of the hierarchy) was like note data without text, so using that, create a folder, make one note in it as one file, and give the title I wrote a program in Python that creates text data with file names, and converted notes at once.

After that, I threw it into DropBox's Write folder and synced it with my Mac, iPhone, and iPad.

At first I tried to do it with AppleScript, but I didn't get the hang of character encoding, and Write wasn't compatible with AppleScript. So, when I was writing in Perl, which I wasn't used to, an acquaintance told me that "Python is easy", so when I wrote it while studying with information on the Web, it was relatively easy as advised.

A Python program that splits a text file for Write

It's a Python beginner's code, so it's childish and embarrassing, but I decided to expose it in the hope of advice. Any suggestions, advice, or suggestions are welcome.

SepNote.py


#!/usr/bin/python
# -*- coding: utf-8 -*-

import codecs
import os

odir = 'MacNote'
otitle = ""
odata = ""
ostart = 0

fin  = codecs.open('conv.txt','r','utf-8')

for row in fin:
	linedata = row.rstrip()
	if  '== MacNote title ==' in linedata: 
		ostart = 1
	elif '== MacNote text ==' in linedata: 
		ostart = 2
	elif '== MacNote end ==' in linedata:
		if len(odata)< 2:
			odir = otitle
		else:
			if not os.path.exists(odir): os.mkdir(odir)
			ofname = otitle.replace('/', '_')
			if len(ofname)>20: ofname = ofname[0:20]
			ofneme = odir + '/' + ofname + '.txt'
			fout_utf = codecs.open(ofneme,'w','utf-8')
			fout_utf.write(u'■' + otitle + '\n')
			fout_utf.write(odata)
			fout_utf.close()
		otitle = ''
		odata = ''
		ostart = 0
	elif ostart == 1:
		otitle = linedata
		odata = ''
	else:
		odata = odata + linedata + '\n'

fin.close()

Recommended Posts

Data retrieval from MacNote3 and migration to Write
Compress python data and write to sqlite
[Kaggle] From data reading to preprocessing and encoding
[Python] How to read data from CIFAR-10 and CIFAR-100
Automatic data migration from yahoo root lab to Strava
[Python / Ruby] Understanding with code How to get data from online and write it to CSV
From Elasticsearch installation to data entry
SIGNATE Quest ① From data reading to preprocessing
Bind to class to read and write YAML
Migration from Python2 to Python3 (Python2 is rebuilt as a virtual environment and coexists)
Porting and modifying doublet-solver from python2 to python3.
Dump SQLite3 data and migrate to MySQL
How to write pydoc and multi-line comments
[Python] From morphological analysis of CSV data to CSV output and graph display [GiNZA]
Data preprocessing (2) Data is changed from Categorical to Numerical.
[Python] Flow from web scraping to data analysis
Write CSV data to AWS-S3 with AWS-Lambda + Python
Data cleaning How to handle missing and outliers
How to write async and await in Vue.js
[AWS] Migrate data from DynamoDB to Aurora MySQL
Sum from 1 to 10
Give latitude and longitude point sequence data and try to identify the road from OpenStreetMap data
How to scrape image data from flickr with python
Send log data from the server to Splunk Cloud
Send data from Python to Processing via socket communication
Try to divide twitter data into SPAM and HAM
It's not easy to write Python, it's easy to write numpy and scipy
Write tests in Python to profile and check coverage
Write data to KINTONE using the Python requests module
DataNitro, implementation of function to read data from sheet