Running a Script before processing files?

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Running a Script before processing files? Sun Aug 26, 2007 3:30 pm • by polymathic
Greetings,

I'm trying to run a little script that wakes up a desktop Mac on my home network and mounts a set volume before Hazel moves a set of files to that volume.

Ideally, if a set of files is older than a week in my download folder, Hazel would run a script like this:

tell application "WakeOnLan"
wakeup "iMac"
delay 2
quit

end tell
mount volume "afp://USER:password@[xxxx:5:0:0:203:xxxx:fe6a:9672]/Backup"

Then it would move my files. Somehow, Hazel wants to apply the script to each file that meets the criteria, which makes the script pop up multiple dialogues, etc. Is there a way to have the script run once, then for Hazel to process the files?

Thanks in advance for any help.
polymathic
 
Posts: 6
Joined: Sun Aug 26, 2007 3:15 pm

Mon Aug 27, 2007 11:54 am • by Mr_Noodle
Unfortunately for your purposes, Hazel works on each file individually. I've thought about some way of batching but it wouldn't work like you'd want it to since it's hard to predict what the expected begin and end points of a batch are. It's something I'm still thinking about.

For now, here's a workaround:
- Have the rule move the files to special destination folder
- Do sort into subfolders to create a new subfolder giving it a unique name. Use something like the date and hour or somesuch. I don't know what the window of time for a "batch" is for you so you need to figure this out.

- Have Hazel monitor the special destination folder
- Create a rule to watch for folders and run your script.
- When it sees a new subfolder created by the rule above, run your script.
- Descend into the folder and move the files. You may want to add a delay to give the subfolder some time to collect it's contents. You can add a condition using Date Created or Date Added for this.

This is just off the top of my head so it may require a good bit of tweaking.

The other solution is to see if it's possible to have the script not bring up a dialog.

Sorry, this is a bit more involved but hopefully it will give you a starting point. Let me know if you need any more help.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Tue Aug 28, 2007 7:31 pm • by polymathic
Thanks for the advice. I will try this.
polymathic
 
Posts: 6
Joined: Sun Aug 26, 2007 3:15 pm

Tue Aug 28, 2007 9:03 pm • by polymathic
This works, but how do I descend into the folder?

Basically, I've managed to get my stuff collected and transferred to my firewire drive on the network, but only as a bundled folder created by the "Sort into Folder" rule.

Ideally, I just want the folder's content to be transferred, then let Hazel delete the empty folder left behind. Is that possible? Is there a rule for transferring a newly created folder's content?

TIA
polymathic
 
Posts: 6
Joined: Sun Aug 26, 2007 3:15 pm

Wed Aug 29, 2007 1:01 pm • by Mr_Noodle
You can descend into the folder using "Run rules on folder contents". The rule would look something like this:

"If Kind is Folder, Run rules on folder contents"

This will cause Hazel to descend into the folder and then run all the rules on the files inside. You would then also have a rule to move the files.

If you only want Hazel to go into that folder every x minutes/hours (i.e. doing things in batch), you can add a condition to the above rule like

"Date Last Matched is not in the last x minutes/hours/days"

That basically makes it such that the rule won't get run too often.

To clean out an empty folder, add the following before the rule described above:

"If Kind is Folder and Size is 0, Move to Trash"

Let me know how it works out. It's a bit convoluted and at this point it might be easier to have the script use some sort of file lock but there it is.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Sat Sep 01, 2007 6:30 pm • by polymathic
I can't figure this one out. I've managed to get my script run successfully, but I cannot transfer the files only. I keep on getting the entire folder. My rule on the pre-transfer folder goes like this:
If kind is folder
Do: Run Apple Script Wake iMac
Run Rules on folder content
Move file to (volume on iMac)

This transfers the entire folders, and not the file therein.

I've tried some variations by breaking down the rules and following your advice, but those do not work at all for some reason. Nothing transfers. Here is one variation pre-transfer set of rules that don't work at all:
1) If Kind is folder RUN Applescript Wake iMac
2) If Kind is folder
Then Run Rules on folder content
THen Move file to (volume on iMac)
3) A Delete Empty Folder Rule

This way it doesn't work at all.

Is there a way just to move the files contained in the folder? I'm a bit stumped here.

Thanks for your help.
polymathic
 
Posts: 6
Joined: Sun Aug 26, 2007 3:15 pm

Tue Sep 04, 2007 2:55 pm • by Mr_Noodle
I think you need to split up the "Run rules on folder contents" and the "move" actions. You are matching against a folder, so while "Run rules..." is made for operating on folders, the move action in the same rule is also working on the folder. Break that move action into its own rule. If you want, you can set it to match "Kind is not folder" to make sure you do not match those though it's not strictly necessary as the previous rule already matches against folders.

Let me know if that helps.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thu Sep 06, 2007 3:23 pm • by polymathic
It simply won't work. Either my rule-set moves the entire folder after running my script, or I must remove the script component for the files to transfer alone (and manually run my script). At this point, I've given up, as I have already spent more energy trying to automate this task than a year of manually moving these files would.
polymathic
 
Posts: 6
Joined: Sun Aug 26, 2007 3:15 pm

Fri Sep 07, 2007 12:01 am • by IDontDoWindows
I have a question. As I understand it, if a set of files is more than one week old, Hazel activates a script to mount a volume and then moves the file to that volume. Is that correct?

Is the only thing that Hazel is doing, besides checking to see if a set of files is more than a week old, is moving the files? (If it is, why not have the script move the files?)
IDontDoWindows
 
Posts: 57
Joined: Sun Jan 07, 2007 5:43 am

Fri Sep 07, 2007 12:13 pm • by polymathic
I guess that's an idea. This was my first script, and getting a script to wake my iMac, and mount a volume on my firewire drive as already a breakthrough. I'll have to look into it, but I have no idea how to do that.
polymathic
 
Posts: 6
Joined: Sun Aug 26, 2007 3:15 pm

Fri Sep 07, 2007 1:08 pm • by IDontDoWindows
Post your script. Let's see what we're working with.
IDontDoWindows
 
Posts: 57
Joined: Sun Jan 07, 2007 5:43 am


Return to Support