Hi I wrote a python script to get the size of the file of which I have URL I copied from browser or anywhere; I wanted to create a global keyboard shortcut so I tried to create using Automator > Service > Run a shell Script and selected \usr\bin\python

and pasted the below script to execute:

from pySan import utils
import Tkinter as tk
import urllib
import os
import sys

def main():

        root = tk.Tk()

        # get text from clipboard
        data =  root.clipboard_get()

        if not data:
                print "nothing in clipboard to get file size."

        site = urllib.urlopen(data)
        meta = site.info()

        if meta.keys():
                contentLength = meta.get("Content-Length", None)
                if not contentLength:
                        print "Failed to retrieve or no data available for size"
                length = int(contentLength)
                print "Size of %s: %s " % (os.path.basename(data), ''.join(utils.sizeof(length)) )

if __name__ == '__main__':

but it seems to give error, workflow failed. what am I doing wrong .

  • 1
    Did your really select \usr\bin\python or was it /usr/bin/python – user151019 Oct 11 '15 at 16:34
  • I probably misstyped in SE, as I didnt copied pasted exactly from Automator's window. – Ciasto piekarz Oct 12 '15 at 4:52

You must log in to answer this question.

Browse other questions tagged .