Moving Containing Folder of A File

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

Re: Moving Containing Folder of A File Wed Aug 25, 2010 3:20 pm • by Mr_Noodle
I don't think you need this script to do that. You can just make a rule to empty folders with a size of 0. The only caveat here is that sometimes you get invisible files in a folder (like .DS_Store) which can screw this up but it should work in most cases.
Mr_Noodle
Site Admin
 
Posts: 11240
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Moving Containing Folder of A File Sun Oct 24, 2010 8:33 am • by gasman1
This had me flummoxed, until I realised that "the run on all subfolders" routine I had as the first rule was conflicting, now I have a rule to find all empty folders and trash them as the first rule, and there are no problems.
gasman1
 
Posts: 1
Joined: Sun Oct 24, 2010 8:31 am

Re: Moving Containing Folder of A File Sun Nov 28, 2010 12:44 pm • by gcoghill
Can't figure out how to use this to accomplish the following:

- Hazel watches Folder A
- Folder A receives new files & folders (Folders A1, A2, etc.)
- Folder A receives a new folder ("Folder A1") with a PDF contained
- tag Folder A1 with "PDF"

The problem is that Folder A will contain other files (files not in folders), and I have rules needing to match those files as well. Your description says that subsequent actions will be made on the parent folder, but I don't want Hazel going up the hierarchy above Folder A.
gcoghill
 
Posts: 290
Joined: Tue Sep 18, 2007 8:09 am
Location: Kent, OH

Re: Moving Containing Folder of A File Tue Nov 30, 2010 12:12 pm • by Mr_Noodle
Subsequent actions within the same rule will work on the parent. It won't go recursively upwards nor will it affect processing of other files (unless they hit that action).
Mr_Noodle
Site Admin
 
Posts: 11240
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Moving Containing Folder of A File Thu Apr 21, 2011 4:46 pm • by kingsinger
Mr_Noodle wrote:Actually, try this:
Code: Select all
tell application "Finder"
   set posix_parent_dir to POSIX path of (container of (item theFile) as text)
   
end tell
return {hazelSwitchFile:posix_parent_dir}




Is there a way to handle a situation like this:

Say, you have say a sub-folder called "Album Name" inside the download folder.

Inside that sub-folder you have two sub-folders, each corresponding to a compact disc worth of music (e.g., disc 1 and disc 2, because it's a multi-disc album). Inside each of those two sub-folders are a series of mp3s.

Running the applescript above did a good job of moving the folders titled disc 1 and disc 2 along wit the mp3s inside to a destination of my choosing. But it did not move the folder one level above that, which has the Album name.

Is there anyway to account for that contingency?
kingsinger
 
Posts: 1
Joined: Thu Apr 21, 2011 3:13 pm

Re: Moving Containing Folder of A File Mon Apr 25, 2011 1:55 pm • by Mr_Noodle
What do you want it to do with the album folder?
Mr_Noodle
Site Admin
 
Posts: 11240
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Moving Containing Folder of A File Fri May 27, 2011 9:38 pm • by lookez69
Everytime i try to run
Code: Select all
my hazelProcessFile(leFiche)

on hazelProcessFile(leFiche)
   try
   tell application "Finder"
      activate
      set leDossier to container of (selection as alias)
      move leDossier to folder "users:me:documents:" of startup disk
   end tell
   on error
   display dialog "Ummmm.... What?"
   end try
end hazelProcessFile


Im getting the Ummmm... what error. What I'm doing is to run this rule on subfolders and check if there is a file of a certain extension i created (.xtp, just for testing this) but it never works :(
lookez69
 
Posts: 2
Joined: Fri May 27, 2011 9:13 pm

Re: Moving Containing Folder of A File Mon May 30, 2011 10:20 pm • by Mr_Noodle
I don't understand the point of this script. It doesn't operate on the file passed in. If you want to search any subfile for one with that extension, then have a rule to match files with that extension and another to match folders and descend into them. Please read this sticky article:

viewtopic.php?f=4&t=470

And if you want to operate on a different file/folder, read this article (which is posted earlier in this thread):

viewtopic.php?p=1545#p1545
Mr_Noodle
Site Admin
 
Posts: 11240
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Moving Containing Folder of A File Fri Mar 30, 2012 4:42 pm • by papo
Mr_Noodle wrote:Actually, try this:
Code: Select all
tell application "Finder"
   set posix_parent_dir to POSIX path of (container of (item theFile) as text)
   
end tell
return {hazelSwitchFile:posix_parent_dir}


What this script does is re-target the file being processed to its parent. Any subsequent Hazel actions will operate on the parent folder. It uses a new feature in 2.2 which allows you to return a record with some special values to communicate back to Hazel (check the help for more details).

Also, if you are putting this in an external script (instead of in the rules itself), remember to add the handler around it.

This script differs from the above in that it doesn't do the move for you but it's probably better to use Hazel's built-in action for that anyways.



Any way to get it, not to the parent path, but one level up from where the wiles reside?

For example:

I have the following scenario:

I'm monitoring Folder 0.

So it's

Folder 0 (iTunes Music Folder)
Folder 1 (Unknown Album Artist)
Folder 2 (Last Day) "name of album"
aa.mp3
bb.mp3
cc.mp3
dd.mp3

Right now, I am looking for when all mp3s have Latest Modified Date after 2 minutes, color the folder blue, so I know it is safe to move the folder.

I am using the applescript you provided, but when the rule runs, it is setting the color on Folder 1. I need it to set the color on the folder that actually contains the files, which is Folder 2.

Any pointers on how to set the applescript to just go one level up, instead of the parent directory?
papo
 
Posts: 15
Joined: Wed Mar 28, 2012 4:43 pm

Re: Moving Containing Folder of A File Sat Mar 31, 2012 8:57 pm • by a_freyer
silvine wrote:Is there anyway I can tailor this script to trash empty folders in my download folder?


Trashing empties in the downloads folder is much simpler within Hazel:

Code: Select all

if (all) of the following....
   Kind is FOLDER
   Size is 0 BYTES

Then
   Move file to TRASH
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Moving Containing Folder of A File Mon Apr 02, 2012 12:34 pm • by Mr_Noodle
Actually, with 3.0, I believe this script is no longer needed. Just use the "any/all sub-files/folders" pop-up.

For your case, you don't even need to do that. You can base it off of the folder's size or subfile count.
Mr_Noodle
Site Admin
 
Posts: 11240
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Moving Containing Folder of A File Sun Dec 22, 2013 8:08 pm • by jhoogeboom
Like papo I'm also looking for this:

"Any way to get it, not to the parent path, but one level up from where the files reside?"
jhoogeboom
 
Posts: 2
Joined: Sun Dec 22, 2013 7:59 pm

Re: Moving Containing Folder of A File Mon Dec 23, 2013 3:31 pm • by Mr_Noodle
Please post a separate topic in the Support forum.
Mr_Noodle
Site Admin
 
Posts: 11240
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Moving Containing Folder of A File Tue Dec 24, 2013 10:10 am • by jhoogeboom
Hi,

I was about to, but then I solved it, I had two different interpretations of the rules.

1. that the rules would act on all files in that folder, including recursion in subfolders ( i keep forgetting this). But you need the subfolders *trick/hack*.
2. the script passes on the result to the next action, not rule, so that's why it never triggered.

So just posting this as reference here for people making the same mistakes.
jhoogeboom
 
Posts: 2
Joined: Sun Dec 22, 2013 7:59 pm

Previous

Return to Tips & Tricks - DO NOT POST QUESTIONS