Python Scripts

I'm trying to use Hazel to trigger a python script to rename files by adding a code to the front.
Here is what I have in Hazel:
Name:RenameCueSheet
If any of the following conditions are met:
Extension is pdf
Do the following to the matched file or folder:
Display notification with pattern: Rule running
Run shell script embedded script
which then has:
Shell: /bin/bash
Use $1 to refer to the file being processed.
python /Users/ronbrown/Dropbox/Python/test.py $1
When I force the script to run I see this in the log:
2014-11-17 20:20:51.310 hazelworker[24162] Processing folder Upload (forced)
2014-11-17 20:20:53.415 hazelworker[24162] tour_10.xlsx.pdf: Rule RenameCueSheet matched.
2014-11-17 20:20:53.415 hazelworker[24162] Hazel Alert: Rule running
2014-11-17 20:20:53.415 hazelworker[24162] [Custom Message] Hazel Alert: Rule running
2014-11-17 20:20:53.453 hazelworker[24162] [Error] Shell script failed: Error processing shell script on file /Users/ronbrown/Dropbox/MAFW/Upload/tour_10.xlsx.pdf.
2014-11-17 20:20:53.454 hazelworker[24162] Shellscript exited with non-successful status code: 1
but when I run the python script from the terminal:
RBs-iMac-2:Upload ronbrown$ pwd
/Users/ronbrown/Dropbox/MAFW/Upload
RBs-iMac-2:Upload ronbrown$ python /Users/ronbrown/Dropbox/Python/test.py tour_10.xlsx.pdf
RBs-iMac-2:Upload ronbrown$
The script runs successfully.
Here is the python file:
import os
import sys
import csv
# check that input name is given
if len(sys.argv) != 2:
print "Usage: python test.py <name>"
sys.exit()
#read in the mapping file of sheet # to tour #
with open('/Users/ronbrown/Dropbox/Python/mapping.csv', mode='rU') as infile:
reader = csv.reader(infile, dialect=csv.excel)
mydict = {rows[0]:rows[1] for rows in reader}
name = sys.argv[1]
tour_num = name[name.find('_')+1:name.find('.')]
sheet_num = mydict[tour_num]
new_name = "/Users/ronbrown/Dropbox/MAFW/Upload/renamed/" + sheet_num + '-' + name[:name.find('.xlsx')] + name[name.find('.xlsx')+len('.xlsx'):]
os.rename(name,new_name)
Any ideas?
Here is what I have in Hazel:
Name:RenameCueSheet
If any of the following conditions are met:
Extension is pdf
Do the following to the matched file or folder:
Display notification with pattern: Rule running
Run shell script embedded script
which then has:
Shell: /bin/bash
Use $1 to refer to the file being processed.
python /Users/ronbrown/Dropbox/Python/test.py $1
When I force the script to run I see this in the log:
2014-11-17 20:20:51.310 hazelworker[24162] Processing folder Upload (forced)
2014-11-17 20:20:53.415 hazelworker[24162] tour_10.xlsx.pdf: Rule RenameCueSheet matched.
2014-11-17 20:20:53.415 hazelworker[24162] Hazel Alert: Rule running
2014-11-17 20:20:53.415 hazelworker[24162] [Custom Message] Hazel Alert: Rule running
2014-11-17 20:20:53.453 hazelworker[24162] [Error] Shell script failed: Error processing shell script on file /Users/ronbrown/Dropbox/MAFW/Upload/tour_10.xlsx.pdf.
2014-11-17 20:20:53.454 hazelworker[24162] Shellscript exited with non-successful status code: 1
but when I run the python script from the terminal:
RBs-iMac-2:Upload ronbrown$ pwd
/Users/ronbrown/Dropbox/MAFW/Upload
RBs-iMac-2:Upload ronbrown$ python /Users/ronbrown/Dropbox/Python/test.py tour_10.xlsx.pdf
RBs-iMac-2:Upload ronbrown$
The script runs successfully.
Here is the python file:
import os
import sys
import csv
# check that input name is given
if len(sys.argv) != 2:
print "Usage: python test.py <name>"
sys.exit()
#read in the mapping file of sheet # to tour #
with open('/Users/ronbrown/Dropbox/Python/mapping.csv', mode='rU') as infile:
reader = csv.reader(infile, dialect=csv.excel)
mydict = {rows[0]:rows[1] for rows in reader}
name = sys.argv[1]
tour_num = name[name.find('_')+1:name.find('.')]
sheet_num = mydict[tour_num]
new_name = "/Users/ronbrown/Dropbox/MAFW/Upload/renamed/" + sheet_num + '-' + name[:name.find('.xlsx')] + name[name.find('.xlsx')+len('.xlsx'):]
os.rename(name,new_name)
Any ideas?