Clearing Notability document backgrounds
inyourfaceplate last edited by inyourfaceplate
This is an appex extension script to remove PDF and color backgrounds from Notability documents. To use, open a doc in Notability, click share, use the Note format, choose Pythonista 3, choose this script. You will then get a ne "open in" dialog. Choose Notability from that dialog to re-import the modified doc.
The script treats the note as a zip file, unpacks it, removes any PDFs, edits Session.plist to change the bg color to white, then archives the result.
- Notability's format could change at any time and break this script, so use it at your own risk!!
- I didn't try to use pip, so I 'installed' the biplist module by copy pasting it into my lib directory. I was not able to get plistlib to read the plist file.
- camelCase var names, sorry!
#coding: utf-8 import console, shutil, appex, os.path, zipfile, os, glob, re, plistlib # Install biplist (I could not get plistlib to read the plist file, even # when I used fmt=plistlib.FMT_BINARY)) # Rather than using pip, I just put the contents of this url in ./lib/biplist.py # https://raw.githubusercontent.com/wooster/biplist/master/biplist/__init__.py from lib.biplist import * tmpPath = './jtziptmp/' extractedPath = './jtziptmp/extracted/' tmpFileName = 'tmpfile.zip' newFileName = tmpPath+os.path.basename(appex.get_file_path())+'_bgstripped.note' shutil.rmtree(tmpPath) os.mkdir(tmpPath) os.mkdir(extractedPath) shutil.copy(appex.get_file_path(),tmpPath+tmpFileName) shutil.unpack_archive(tmpPath+tmpFileName,extractedPath) pattern = "^.*pdf$" mypath = extractedPath for root, dirs, files in os.walk(mypath): for file in filter(lambda x: re.match(pattern, x), files): os.remove(os.path.join(root, file)) # remove the pdf bg pattern = "^Session.plist$" mypath = extractedPath for root, dirs, files in os.walk(mypath): for file in filter(lambda x: re.match(pattern, x), files): plist = readPlist(os.path.join(root, file)) plist['$objects']['paperIndex'] = 12 # set white bg writePlist(plist,os.path.join(root, file)) shutil.make_archive(newFileName,'zip',extractedPath) shutil.move(newFileName+'.zip',newFileName) console.open_in(newFileName)
tonyclark last edited by
This post is deleted!