Page 1 of 1

Move your file with the filename

PostPosted: Sat Mar 05, 2016 7:59 am
by Ksooos
This rules watches for any files with this pattern @Var1--Var2 and immediately use a python script to move the file.
Var1 is the destination path and Var2 is the filename.

Example: You rename the file like this @Documents-Serie-GOT--ep1.mkv then the script move the file in /Users/user1/Documents/Serie/GOT

RULES:
If ALL of the following conditions are met

Name matches @ ... -- ...

Do

Run shell script FunctionMove.py

File FunctionMove.py
Code: Select all
#!/usr/bin/python

import sys,os
import shutil

g=str(sys.argv[1])
name= g.split("@")[1].split('--')
homepath="/Users/user1/"
path= homepath+name[0].replace('-','/')

if os.path.exists(path):
    file=path+'/'+name[1]
    if not os.path.isfile(file):
        shutil.move(g,file)

Re: Move your file with the filename

PostPosted: Mon Mar 07, 2016 11:51 am
by Mr_Noodle
Unless I'm missing something, it seems you can do this using Hazel's built-in capabilities (i.e. without a script). Search for "match patterns" in the help.