move files and create alias in original location

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

Moderator: Mr_Noodle

hello, i'm new to hazel.

i would like to create a rule which applies the following rule to all files in a folder (and its subfolder)

move big files to a repository on another volume and then create an alias to the moved file in its original location.

i have searching the forums for hours, but so far i haven't found how to do this. maybe it is just super easy.

any help with be appreciated.

thanks a lot
robert
robertggg
 
Posts: 1
Joined: Sat Jun 16, 2012 9:59 am

Check the sticky article near the top of the forum about going into subfolders.

To create the alias back at the source, you need to something odd like create the alias at the folder being monitored and then sort into subfolder using the "source folder" attribute. Search the help on source folder to see how to use it.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:Check the sticky article near the top of the forum about going into subfolders.

To create the alias back at the source, you need to something odd like create the alias at the folder being monitored and then sort into subfolder using the "source folder" attribute. Search the help on source folder to see how to use it.



I have a very similar use case and am struggling to figure out the proper order of events. I use Aperture to load pictures and movies from my cameras' SD cards. The files are distributed automatically by Aperture into folders within my Pictures folder. Once that's done I would like to have Hazel take care of moving the movies to a duplicate folder hierarchy within the Movies folder, and leave an alias of the movie file into the corresponding picture folder.
At this point I have a rule set that works fine for the task of recursively going through the folder hierarchy and moving the movie files to their proper destination. However, I haven't been able to figure out how to leave the aliases behind.
Right now I have Hazel monitor the top level folder with two rules, one for traversing the folders and the other to process the movie files. That second rule has to perform multiple actions:
(1) create the alias
(2) put the alias back in the original folder (because right now they are generated one level above)
(3) move the original file

I have tried different permutations of the order of these operations but they all fail because it seems that in the end Hazel has to process two different groups of files differently, the movie files themselves and the aliases, and that can't be accomplished in a single rule. For instance, it appears that once a file alias is created by Hazel any subsequent processing tasks are applied to the alias instead of the original file. So for instance the following rule will create aliases and then move them to the Movies folder, which is not the intent:

    If all of the following conditions are met
    Kind is Movie
    Do the following to the matched file or folder:
    Make alias in folder enclosing folder
    Sort into subfolder with pattern source folder (use folder name only)
    Move to folder: Movies (copy folder structure from monitored folder)

I just started evaluating Hazel for this task so it's highly likely I'm overlooking something and any help would be greatly appreciated.

As a side note: is there a way to avoid the creation of the aliases in the parent folder?

Xavier
X-C-L
 
Posts: 6
Joined: Sun Dec 29, 2013 10:51 pm

You might be able to rig something using the source folder attribute. Something like:

- Move the file to the "mirror" folder.
- Create the alias at the monitored folder.
- Sort into subfolder (which would be the alias) using the "source folder" attribute, setting it from the monitored folder.

That said, I'd advise against manipulating files after you imported them into Aperture. They are Aperture's data files at that point and while it may seem to work now, it is a bit risky and can break.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:You might be able to rig something using the source folder attribute. Something like:

- Move the file to the "mirror" folder.
- Create the alias at the monitored folder.
- Sort into subfolder (which would be the alias) using the "source folder" attribute, setting it from the monitored folder.

That said, I'd advise against manipulating files after you imported them into Aperture. They are Aperture's data files at that point and while it may seem to work now, it is a bit risky and can break.


Unfortunately, something goes wrong with the path when the aliases are moved. Here is a test configuration and the result of the rule set:

Before applying the rules:

The Monitored Folder "HazelTest" is located in Documents. It contains the following subfolders and files:
/2008/testFile_2008.mp4
/2009/2009-12-03/testFile_2009-12-03.mp4
/2009/2009-12-12/testFile_2009-12-12.mp4

The target folder for the move is "Movies - Test," located within Movies. The target folder is initially empty.

Hazel rules for the monitored folder:
Rule 1:
If all of the following conditions are met
Kind is folder
Do the following to the matched file or folder:
Run rules on folder contents

Rule 2:
If all of the following conditions are met
Kind is Movie
Do the following to the matched file or folder:
Move to folder: "Movies - Test" with option: copy folder structure: "from monitored folder"
Make alias in folder: "enclosing folder"
Sort into subfolder with pattern: "source folder" with option "use path from monitored folder"

After applying the rules:

All folders in Documents/HazelTest are empty

The target folder Movies/Movies - Test now contains:
2008/testFile_2008.mp4
2008/testFile_2008-1.mp4 (alias)
2009/2009-12-03/testFile_2009-12-03.mp4
2009/2009-12-12/testFile_2009-12-12.mp4
2009/2009/2009-12-03/testFile_2009-12-03-1.mp4 (alias)
2009/2009/2009-12-12/testFile_2009-12-12-1.mp4 (alias)

So the files were moved as expected but the aliases were not moved back to the original location. Additionally there seems to be an issue with the nesting level for the contents of the 2009 folder.


I'm now trying to run an AppleScript to create the alias before the file gets moved. For some reason, the following generates an error:
Code: Select all
tell application "Finder" to make new alias at (path to theFile) to file (theFile)


2013-12-30 18:31:24.296 hazelworker[16782] 2009-12-12: Rule Tree matched.
2013-12-30 18:31:24.299 hazelworker[16782] testFile_2009-12-12.mp4: Rule Move movie file and keep alias using AppleScript matched.
2013-12-30 18:31:24.483 hazelworker[16782] [Error] AppleScript failed: Error executing AppleScript on file /Users/X-C-L/Documents/HazelTests/2009/2009-12-12/testFile_2009-12-12.mp4.
2013-12-30 18:31:24.483 hazelworker[16782] AppleScript error: {
NSLocalizedDescription = "Finder got an error: Can\U2019t make alias \"Macintosh HD:Users:X-C-L:Documents:HazelTests:2009:2009-12-12:testFile_2009-12-12.mp4\" into type constant.";
NSLocalizedFailureReason = "Can\U2019t make alias \"Macintosh HD:Users:X-C-L:Documents:HazelTests:2009:2009-12-12:testFile_2009-12-12.mp4\" into type constant.";
OSAScriptErrorAppAddressKey = "<NSAppleEventDescriptor: [0x0,10010 \"Finder\"]>";
OSAScriptErrorAppNameKey = Finder;
OSAScriptErrorBriefMessageKey = "Can\U2019t make alias \"Macintosh HD:Users:X-C-L:Documents:HazelTests:2009:2009-12-12:testFile_2009-12-12.mp4\" into type constant.";
OSAScriptErrorExpectedTypeKey = "<NSAppleEventDescriptor: 'enum'>";
OSAScriptErrorMessageKey = "Finder got an error: Can\U2019t make alias \"Macintosh HD:Users:X-C-L:Documents:HazelTests:2009:2009-12-12:testFile_2009-12-12.mp4\" into type constant.";
OSAScriptErrorNumberKey = "-1700";
OSAScriptErrorOffendingObjectKey = "<NSAppleEventDescriptor: 'alis'($00... hexadecimal gibberish ... 00$)>";
OSAScriptErrorRangeKey = "NSRange: {0, 0}";
}
Time for me to learn a bit more AppleScript...


Regarding Aperture's behavior: In my case I don't let Aperture move new files into the Aperture library. They go instead into subfolders in the Pictures folder. This makes life easier for backup purposes. The Aperture library itself contains thumbnails, previews and faces. With this setup Aperture does not lose track of files when I move them manually or rename them with Finder. I was hoping this behavior would be preserved when using Hazel.

Xavier
X-C-L
 
Posts: 6
Joined: Sun Dec 29, 2013 10:51 pm

Update: solution using AppleScript to create file alias.

The following rule set will move all movie files from any subfolder within the monitored folder to an identical folder structure within the folder "Movie - Test". An alias to the moved files is left at their original location.

Rule 1:
If all of the following conditions are met
Kind is folder
Do the following to the matched file or folder:
Run rules on folder contents

Rule 2:
If all of the following conditions are met
Kind is Movie
Do the following to the matched file or folder:
Run AppleScript embedded script
Move to folder: "Movies - Test" with option: copy folder structure: "from monitored folder"

Embedded script:
Code: Select all
tell application "Finder"
   set destinationFolder to container of theFile
   make new alias file at destinationFolder to theFile
end tell


It's possible the same functionality can be achieved with Hazel rules and actions without scripting but I have not figured that out yet.

Xavier
X-C-L
 
Posts: 6
Joined: Sun Dec 29, 2013 10:51 pm

You do not create the alias in the enclosing folder. That only goes one level up from wherever the file is at the moment. What you do is set it to HazelTest and then sort it from there using the source folder attribute. I don't think a script is necessary for this.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:You do not create the alias in the enclosing folder. That only goes one level up from wherever the file is at the moment. What you do is set it to HazelTest and then sort it from there using the source folder attribute. I don't think a script is necessary for this.


I see now, makes sense. So the updated rule is as follow:

Rule 2:
If all of the following conditions are met
Kind is Movie
Do the following to the matched file or folder:
Move to folder: "Movies - Test" with option: copy folder structure: "from monitored folder"
Make alias in folder: "HazelTest"
Sort into subfolder with pattern: source folder (use path from monitored folder)


A minor feature request: the rule set could be more easily exported and applied to another top level folder if in the folder browser that opens for the "make alias" action, we had the option of selecting "monitored folder" instead of actually selecting "HazelTest". I imagine "monitored folder" could be in the same subsection as "enclosing folder". Now, would that be confusing when the two are one and the same?

I must say that so far I'm really impressed by Hazel's features. And likely I've only scratched the surface.

X
X-C-L
 
Posts: 6
Joined: Sun Dec 29, 2013 10:51 pm

Thanks for the suggestion. I had considered adding that a while back but hadn't come up with any actual use cases for it so I punted.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support