Move your file with the filename

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

Move your file with the filename 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)
Ksooos
 
Posts: 1
Joined: Sat Mar 05, 2016 6:52 am

Re: Move your file with the filename 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.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Tips & Tricks - DO NOT POST QUESTIONS