Skip to content

Instantly share code, notes, and snippets.

@danielsgriffin
Created May 24, 2022 19:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Script to check if file is already in Voice Dream Reader library
"""Script to check if file is already in Voice Dream Reader library.
I use this script w/in another to open the Reader programmatically with
a new file added if it isn't already in the library.:
The following in the terminal will add the FILENAME to the library
even if already used:
open -a "Voice Dream Reader" FILENAME
Python snippet from external script:
if check_vdr_library.is_filename_in_library(FILENAME):
subprocess.Popen(
[
"open",
"-a",
"Voice Dream Reader"
]
)
else:
subprocess.Popen(
[
"open",
"-a",
"Voice Dream Reader",
"/Users/dsg/Documents/pdfs/{}.pdf".format(FILENAME),
]
)
"""
# Imports
import os
# Constants
# This may be different if you do not have Preference > Cloud Sync turned on.
# change 'dsg' for your username.
VDR_LIBRARY_DIR = "/Users/dsg/Library/Mobile Documents/iCloud~com~voicedream~reader/Documents/Library/"
# Body
def generate_filenames():
"""Generator expressions returning each filename in the library."""
for folder in os.listdir(VDR_LIBRARY_DIR):
if os.path.isdir(VDR_LIBRARY_DIR+folder):
for filename in os.listdir(VDR_LIBRARY_DIR+folder):
if filename.endswith(".pdf"):
yield filename
def is_filename_in_library(checking_filename):
"""Returns bool if checking_filename in library.
check_filename: str w/ or w/o .pdf
"""
for filename in generate_filenames():
if checking_filename in filename:
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment