Skip to content

Instantly share code, notes, and snippets.

@cspickert
Created March 19, 2013 19:58
Show Gist options
  • Save cspickert/5199542 to your computer and use it in GitHub Desktop.
Save cspickert/5199542 to your computer and use it in GitHub Desktop.
A quick command line tool for determining the MIME type of a local file as returned by NSURLConnection. Requires Mac OS X.
#!/usr/bin/python
from Foundation import *
def MIMETypeForFileAtPath(path):
url = NSURL.fileURLWithPath_(path)
request = NSURLRequest.requestWithURL_(url)
data, response, error = NSURLConnection.sendSynchronousRequest_returningResponse_error_(request, None, None)
return response.MIMEType()
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("paths", metavar="path", type=str, nargs='+')
args = parser.parse_args()
for path in args.paths:
print MIMETypeForFileAtPath(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment