Skip to content

Instantly share code, notes, and snippets.

@fidiego
Last active October 12, 2015 15:28
Show Gist options
  • Save fidiego/81d8fb96db462d78c61e to your computer and use it in GitHub Desktop.
Save fidiego/81d8fb96db462d78c61e to your computer and use it in GitHub Desktop.
Command for opening photo directories on OSX since Photos gives you a hard time if you try to find the path to an image.
#!/usr/bin/python
import os, sys
from datetime import datetime
def main():
docstring = """
Super Simple Script that opens Mac's Photo Library source directory so you
can get to your pictures etc.
-h prints this page
today opens the directory w/ today's date
[year month day] any args passed after 'photos' will be
concatenated into one directory.
If the directory doesn't exist, you'll get an error.
EXAMPLES:
photos 2015 7 13
photos 2015 07 13
-> $ cd ~/Pictures/Photos\ Library.photoslibrary/Masters/2015/07/13
That's all folks.
"""
ROOT_DIR = '~/Pictures/Photos\ Library.photoslibrary/Masters'
directory = ''
if len(sys.argv) > 1:
if sys.argv[1] == '-h':
print docstring
return
elif sys.argv[1] == 'today':
today = datetime.now()
directory = os.path.join(directory, str(today.year))
directory = os.path.join(directory, str(today.month).zfill(2))
directory = os.path.join(directory, str(today.day).zfill(2))
else:
sub_dirs = sys.argv[1:]
for d in sub_dirs:
directory = os.path.join(directory, d)
print 'opening {}'.format(os.path.join(directory))
directory = os.path.join(ROOT_DIR, directory)
else:
directory = ROOT_DIR
os.system('open {}'.format(directory))
return
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment