Help with Scripting...!

Talk, speculate, discuss, pontificate. As long as it pertains to Hazel.

Moderators: Mr_Noodle, Moderators

Help with Scripting...! Sat Apr 09, 2011 3:13 am • by varyags
I've setup Hazel with TVshows to grab new episodes and automatically download using Transmission, then using TVnamer to rename/sort the episodes into folders.

How could I automatically delete the folder that transmission creates when deleting?

Also, how could I stop hazel from deleting the archive files after extracting?

thanks!
Last edited by varyags on Mon Apr 18, 2011 10:45 am, edited 1 time in total.
varyags
 
Posts: 9
Joined: Sat Apr 09, 2011 3:09 am

Re: Deleting Parent Folder Mon Apr 11, 2011 1:34 pm • by Mr_Noodle
Maybe this thread will help?

viewtopic.php?f=4&t=992

You can't stop Hazel from removing archives after unarchiving but you can copy the archive and then unpack the copy.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Scripting Help Sun Apr 17, 2011 1:31 pm • by varyags
Hi Mr_Noodle, thanks for he reply. I managed to set it up!

I'm trying to do this other thing but unfortunately I have no idea how to use shell scripting or applescripts to do this. Was hoping someone could solve this.

So what I want to do is the following:

1. I have a rule setup to watch /Volumes to see if my external hard drive is connected or not
2. If the external hard drive is found, it's set to start a script (I tried this in automator but it wasn't enough...)
3. The script needs to copy all the contents which does not have a red label set in a folder called TV (~/TV) to a folder on the external hard drive (/HD2TB/TV Shows).
4. I would like to change the label colour to red, when a file is copied from TV to TV Shows (for the files in ~/TV, ideally after the copy was successful).

Here's my idea: I use TVShows to download torrents, then setup Hazel to open up torrents file, Transmission downloads it, then I use TVnamer to rename and move the downloaded show to ~/TV. Then when I connect my external HDD I want it to copy to /TV Shows so that Hazel can then sort it into subfolders using its match function. Then I have a backup copy on my external HDD, and I have a copy on my laptop (with red label).

I managed to get automator to copy and set the label colour, but I could not do "move only red labelled contents" action.

Thanks for the help in advance!
varyags
 
Posts: 9
Joined: Sat Apr 09, 2011 3:09 am

Re: Help with Scripting...! Mon Apr 18, 2011 12:06 pm • by Mr_Noodle
Getting the red label on the original file after the copy is tricky. If you are just worried about not having it copy twice, you can just make the condition like "Date last modified is after date last matched." That should only run when the file has been changed since last time. If not, it won't match that rule and won't copy it again.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Help with Scripting...! Mon Apr 18, 2011 12:13 pm • by varyags
Hi. Thanks for the reply.

At the moment, I have hazel to open an automator workflow when it detects the external hard drive. It does the following:

1. "Get Specified Finder Items" (I select ~/TV)
2. "Get Folder Contents"
3. "Stop if Input is Empty" (customer action I downloaded)
4. "Filter Finder items" find files where all of the following are true: Label is not red.
5. "Stop if Input is Empty"
6. "Label Finder Items" Red
6. "Copy Finder Items" to "HD2TB/TV Shows".

Somehow this screws up and highlights everything in the top hierarchy on the external hard drive HD2TB.

Any ideas?

I was hoping there may be a quick (automator actions seems rather slow, is this just me?) using applescript or shell script...
varyags
 
Posts: 9
Joined: Sat Apr 09, 2011 3:09 am

Re: Help with Scripting...! Wed Apr 20, 2011 2:50 pm • by Mr_Noodle
What are you trying to do? From the looks of it, you just want Hazel to copy over any new files on the external drive. Just have Hazel monitor that folder and do "If date added is after date last matched, copy file to ...". I think that by itself should do it. No need to color files red since the rule condition will not match files that were already copied.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Help with Scripting...! Wed Apr 20, 2011 2:58 pm • by varyags
The problem is that Hazel is watching the /Volume folder whereas the files I want to copy are in another folder. From what I can figure out, hazel's copy action cannot copy files in a different folder from the one that the rule is being run on (?) So I wanted to do this by Automator/Applescript...

The red-label is so that I know that the file has been copied successfully onto the external hard drive, as I sometimes travel with my laptop and not have my hdd connected...

Hope you could help me! Thanks for the responses.
varyags
 
Posts: 9
Joined: Sat Apr 09, 2011 3:09 am

Re: Help with Scripting...! Thu Apr 21, 2011 11:05 am • by Mr_Noodle
Is there a reason you don't have Hazel actually monitor the folder with the files in it? If you do it that way, you won't need Automator nor would you need to color the files.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Help with Scripting...! Thu Apr 21, 2011 11:16 am • by varyags
If I monitor the folder with the files, then Hazel will try attempt to copy the files even if the hard drive is not connected (am I right?). I read your suggestion elsewhere that if you wanted something done when the external drive is connected, run rules on the /Volumes folder... is this right?
varyags
 
Posts: 9
Joined: Sat Apr 09, 2011 3:09 am

Re: Help with Scripting...! Thu Apr 21, 2011 4:09 pm • by Mr_Noodle
No, it will wait until the drive is mounted. Even if it tried, it would fail and just try again later anyways. Not sure where you read the other thing but I'm guessing it was a different context there. Nonetheless, try the above and see if that works for you.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Help with Scripting...! Fri Apr 22, 2011 4:11 am • by varyags
I will try! thanks
varyags
 
Posts: 9
Joined: Sat Apr 09, 2011 3:09 am

Re: Help with Scripting...! Thu Apr 28, 2011 7:29 am • by varyags
thanks! its working now, didn't realise i could have it so simple!

I've come across yet another hurdle though..

So I got it to copy over to my external hard drive to another folder, now I want it to sort the file into subfolders...

The files are always in this format (say it was an episode of 24)

24 - S01E01 - episode name

Now I got it working so that it gets sorted into

24 / Season 1 /

However, if i don't do digits for the season name, i end up with

"Season 01"

which is fine for seasons that don't go on over 9, but some do, and I was wondering whether there was a way to strip off the 0 from "01", "02" etc.

Thanks again
varyags
 
Posts: 9
Joined: Sat Apr 09, 2011 3:09 am

Re: Help with Scripting...! Thu Apr 28, 2011 10:53 am • by Mr_Noodle
I assume you created a custom token for the season number? If so, and if you defined that token as being composed of digits or a number, then in the pattern where you use it, if you click on the arrow on it, it will bring up a menu. From there, you can set the number of digits.

That said, if, by default, it's showing up that way, I think it's because you made the custom token match something other than numbers. In that case, I'd just fix those to match a number.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Help with Scripting...! Mon May 02, 2011 1:22 pm • by varyags
Thanks! I did not realise that you could change the option on the tokens...

Quick question: if a rule fails, does Hazel count it as being matched? as in would the date last matched alter even if the rule fails?
varyags
 
Posts: 9
Joined: Sat Apr 09, 2011 3:09 am

Re: Help with Scripting...! Mon May 02, 2011 1:28 pm • by Mr_Noodle
Date last matched is only updated when the rule successfully executes on the file.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Open Discussion