Skip to content

Instantly share code, notes, and snippets.

@d108
Last active August 29, 2015 13:57
Show Gist options
  • Save d108/9891043 to your computer and use it in GitHub Desktop.
Save d108/9891043 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Daniel Zhang (張道博)'
"""
Compress and rename a lossless audio file using a hard-coded path.
Following compression, call an AppleScript script that copies the newly
compressed file as an attachment to the currently selected note in Evernote.
Usage:
python compressAndRenameLosslessAudioFile.py
"""
from datetime import datetime as dt
import subprocess
import os
def runCommand(cmd = ''):
"""
Run a system command.
:param cmd: string
:returns: None
"""
if cmd != '':
try:
subprocess.check_call(cmd, shell = True)
except subprocess.CalledProcessError as error:
print 'Exception occurred while calling the process to run ' \
'command: {}'.format(error)
else:
raise Exception('Empty command.')
def conciseNow():
"""
The current date and time.
:returns: string
"""
return dt.now().strftime('%Y-%m-%d (%B %d) %H-%M-%S')
if __name__ == '__main__':
myPath = '${MY_CUSTOM_AUDIO_PATH}'
applescriptPath = '${MY_APPLESCRIPT_PATH}'
os.chdir(myPath)
runCommand(
'afconvert audio-recording-lossless.m4a -o "{}.m4a" -q 127 -b 64000 ' \
'-f m4af -d aac'.format(conciseNow()))
runCommand('osascript {}/copyLastFileAsEvernoteAttachment.scpt'.format(
applescriptPath))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment