Commit 67350ae3 authored by Jonas Neugebauer's avatar Jonas Neugebauer

Added script to generate README.md from script 'frontmatter'

parent ebb7d46a
# osx-script-stuff
A collection of scripts to automate stuff on Max OS X systems.
## Table of contents
1. [Scripts](#scripts)
- [Compose mail](#compose-mail)
- [Save attachments](#save-attachments)
- [Set Caffeine state](#set-caffeine-state)
- [Show Caffeine state](#show-caffeine-state)
- [Compose mail](#compose-mail-1)
- [Save attachments](#save-attachments-1)
- [Vacuum Mail.app index](#vacuum-mailapp-index)
1. [App Index](#app-index)
## Scripts
### Compose mail
- File: [_Airmail/ComposeMail.applescript_](./Airmail/ComposeMail.applescript)
- Apps: [Airmail 2](http://airmailapp.com)
> Quickly compose an email in Airmail 2
- Parameters:
- **SUBJ**: Subject line
- **TESNIP**: Abbreviation of a TextExpander snippet to use as content
- **RECEIPIENTS**: List of recipient mails
- **CC**: List of cc mails
- **BCC**: List of bcc mails
- **SENDR**: Sending account to use
### Save attachments
- File: [_Airmail/SaveAttachment.applescript_](./Airmail/SaveAttachment.applescript)
- Apps: [Airmail 2](http://airmailapp.com)
> Use as a script in Airmail rules to save attachments to the selected folder.
- Parameters:
- **DOWNLOADS**: Folder to save attachments to
### Set Caffeine state
- File: [_Caffeine/ToggleCaffeine.applescript_](./Caffeine/ToggleCaffeine.applescript)
- Apps: Caffeine, [Alfred](http://alfredapp.com)
> Use as Alfred action to activate/deactibvate Caffeins or toggle the state.
### Show Caffeine state
- File: [_Caffeine/alfred_CaffeineStatus.applescript_](./Caffeine/alfred_CaffeineStatus.applescript)
- Apps: Caffeine, [Alfred](http://alfredapp.com)
> Use in Alfred script filter to show Ceffeins state (active or inactive).
### Compose mail
- File: [_Mail/ComposeMail.applescript_](./Mail/ComposeMail.applescript)
- Apps: Mail
> Quickly compose an email in Mail.app
- Parameters:
- **SUBJ**: Subject line
- **TESNIP**: Abbreviation of a TextExpander snippet to use as content
- **RECEIPIENTS**: List of recipient mails
- **CC**: List of cc mails
- **BCC**: List of bcc mails
- **SENDR**: Sending account to use
### Save attachments
- File: [_Mail/SaveAttachment.applescript_](./Mail/SaveAttachment.applescript)
- Apps: Mail
> Use as a script in Mail.app rules to save attachments to the selected folder.
- Parameters:
- **DOWNLOADS**: Folder to save attachments to
- **TRASH_AFTER**: Set to true to trash the mail after saving the attachments
### Vacuum Mail.app index
- File: [_Mail/VacuumIndex.applescript_](./Mail/VacuumIndex.applescript)
- Apps: Mail
> Speed up Mail.app by vacuuming the Envelope Index
## App Index
- **Airmail 2**
- [Compose mail](#compose-mail)
- [Save attachments](#save-attachments)
- **Alfred**
- [Set Caffeine state](#set-caffeine-state)
- [Show Caffeine state](#show-caffeine-state)
- **Caffeine**
- [Set Caffeine state](#set-caffeine-state)
- [Show Caffeine state](#show-caffeine-state)
- **Mail**
- [Compose mail](#compose-mail-1)
- [Save attachments](#save-attachments-1)
- [Vacuum Mail.app index](#vacuum-mailapp-index)
# osx-script-stuff
A collection of scripts to automate stuff on Max OS X systems.
import os, glob, re, yaml
from subprocess import call
TARGET = 'README.md'
TAGS = {
'.applescript': ['(*','*)'],
'.sh': ['# '],
'.py': ['# ']
}
APPS = {
'Alfred': 'http://alfredapp.com',
'TextExpander': 'https://smilesoftware.com/TextExpander/index.html',
'Airmail 2': 'http://airmailapp.com'
}
COMPILER = {
'.applescript': 'osacompile -x -o %s.scpt %s'
}
def parseBlockComment(file, tagOpen, tagClose):
yml = ''
f = open(file, 'r')
try:
if f.readline().startswith(tagOpen):
for line in f:
if line.startswith(tagClose):
break;
yml += line
finally:
f.close();
return yml
def parseLineComment(file, tag):
yml = ''
f = open(file, 'r')
try:
line = f.readline()
if line.startswith(tag):
yml += line[len(tag):]
for line in f:
if not line.startswith(tag):
break;
yml += line[len(tag):]
finally:
f.close();
return yml
_IDS = []
def makeId(label):
_id = re.sub(r'\s+', '-', label.lower())
_id = re.sub(r'\.', '', _id)
__id = _id
i = 1
while _id in _IDS:
_id = '%s-%s' % (__id, i)
i += 1
_IDS.append(_id)
return _id
Y = {}
IDS = {}
files = glob.glob('**/*.*')
for file in files:
name, ext = os.path.splitext(file)
if ext in TAGS:
yml = ''
if len(TAGS[ext]) == 2:
yml = parseBlockComment(file, TAGS[ext][0], TAGS[ext][1])
else:
yml = parseLineComment(file, TAGS[ext][0])
if not yml == '':
try:
yml = yaml.load(yml)
if 'name' in yml and 'description' in yml:
Y[file] = yml
IDS[file] = makeId(yml['name'])
except:
pass
T = open(TARGET, 'w')
INDEX = {}
# Generate header
header = open('_README.md').read();
T.write(header);
T.write('\n\n')
print('\x1b[0;32m>\x1b[0m Added headers from \x1b[0;35m_README.md\x1b[0m to documentation')
# Generate TOC
T.write('## Table of contents\n\n')
T.write('1. [Scripts](#scripts)\n')
for file, yml in iter(sorted(Y.items())):
T.write('\t- [%s](#%s)\n' % (yml['name'], IDS[file]))
T.write('1. [App Index](#app-index)\n')
# Generate docs
T.write('\n## Scripts\n\n')
for file, yml in iter(sorted(Y.items())):
def make_link(app):
if app in APPS:
return '[%s](%s)' % (app, APPS[app])
else:
return app
apps = [a.strip() for a in yml['apps'].split(',')]
for app in apps:
if not app in INDEX:
INDEX[app] = [file]
else:
INDEX[app].append(file)
apps = map(make_link, apps)
T.write('### %s\n' % yml['name'])
T.write('- File: [_%s_](./%s)\n' % (file, file))
T.write('- Apps: %s\n\n' % ', '.join(apps))
T.write('> %s\n\n' % yml['description'])
if 'parameters' in yml and not yml['parameters'] == None and len(yml['parameters']) > 0:
T.write('\n- Parameters:\n\n')
for param, descr in yml['parameters'].items():
# T.write('- **%s** \n\t%s\n' % (param, descr))
T.write('\t- **%s**: %s\n' % (param, descr))
T.write('\n\n')
print('\x1b[0;32m>\x1b[0m Added \x1b[0;35m%s\x1b[0m to documentation' % file)
name, ext = os.path.splitext(file)
if 'compile' in yml and yml['compile'] == True and ext in COMPILER:
call(COMPILER[ext] % (name, file), shell=True)
print('\x1b[0;32m->\x1b[0m Created binary for \x1b[0;35m%s\x1b[0m' % file)
# Generate index
T.write('\n## App Index\n\n')
for app, files in iter(sorted(INDEX.items())):
T.write('- **%s**\n' % app)
for file in files:
T.write('\t- [%s](#%s)\n' % (Y[file]['name'], IDS[file]))
T.close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment