problem using applescript rule

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

Moderator: Mr_Noodle

problem using applescript rule Tue Jul 17, 2012 12:24 pm • by flynn
Hello,
I am setting up hazel to backup my Series folder into my hard drive. My goal is to have all my movies in my hard drive for backup, and only have the ones i'm interested in on my computer as they take a lot of space.
I can't use sync because it will delete files on my hard drive that don't exist on my computer, and I can't use copy because it will either delete files that aren't on my computer when replacing folders on the hard drive, or it will make too many copies of every file and that will take up too much space.

The solution was to go file-by-file. Again, using hazel to do this would be a pain, my series folder is structured in a particular way (Name_Of_Series/Season_num/*movies go here*) both in my movies folder and on my hard drive. I would have to create a copy of the same rule with a destination folder change for every season folder, which seems inefficient to me.

I went on to create an applescript. This applescript will take the path of theFile, filter out the beginning of the name so that only the part /Name_Of_Series/Season_Num/Movie_File remains, then adds it to the path to my series folder in my hard drive. It then checks whether the file exists or not, returning false if it does ( as I do not want to copy the file if it already exists) and true if it doesn't (and then should go on to copy the file).

When I input the first path manually and run that inside applescript editor, it works perfectly well

Code: Select all
set f to "Macintosh HD:jonathanhirsch:Movies:Torrent Series:Dexter:Season 3:Dexter - S03E10.mkv" as string


set num to get number of characters in f
set pathName to characters 51 through num of f as string

set exist to null
try
   set HDf to "Macintosh HD:Volumes:Jono:Series:" & pathName as string
   set f2 to HDf as alias
   set exist to false
on error
   set exist to true
end try
return exist


but when I put it inside hazel, changing 'set f to "Macintosh HD:jonathanhirsch:Movies:Torrent Series:Dexter:Season 3:Dexter - S03E10.mkv" as string' to 'set f to path to theFile as string', hazel returns an error. If I check the preview of the rule, it says that there is a no metadata error.

Image
note: the applescript rule that is supposed to run if the file matches just creates a file in my home directory so that I know whether the rule matched or not. It doesn't move anything. Also, I filtered out names of episodes so that just one would match and prevent spamming and slowing down because all my movies would return errors. I plan to run this rule also only if the folder was modified before the last time hazel checked so that it does not run it too often.

and here are the logs for that file (with debug). They seem huge for the small amount of work I actually thought it would do..

Code: Select all
2012-07-17 23:55:24.285 hazelworker[6947] DEBUG: [PREDICTION] Predicted fire time for file: /Users/jonathanhirsch/Movies/Torrent Series/Dexter/Season 3 and rule Go into Folders: 5828963-12-20 08:00:00.000 Should poll: 0
2012-07-17 23:55:24.285 hazelworker[6947] DEBUG: Recursing into directory: /Users/jonathanhirsch/Movies/Torrent Series/Dexter/Season 3
2012-07-17 23:55:24.286 hazelworker[6947] DEBUG: .DS_Store: File is hidden/invisible. Skipping.
2012-07-17 23:55:24.288 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: labelColor ==[cd] 7 negation: 0 result: 0
2012-07-17 23:55:24.288 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 08:00:00.000
2012-07-17 23:55:24.288 hazelworker[6947] DEBUG: [PREDICTION] Bail out: AND predicate
2012-07-17 23:55:24.288 hazelworker[6947] DEBUG: [PREDICTION] Predicted fire time for file: /Users/jonathanhirsch/Movies/Torrent Series/Dexter/Season 3/Dexter - S03E01.mkv and rule Not All Seen: 5828963-12-20 08:00:00.000 Should poll: 0
2012-07-17 23:55:24.290 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: typeObject isType: "public.folder" negation: 0 result: 0
2012-07-17 23:55:24.290 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 08:00:00.000
2012-07-17 23:55:24.290 hazelworker[6947] DEBUG: [PREDICTION] Bail out: AND predicate
2012-07-17 23:55:24.290 hazelworker[6947] DEBUG: [PREDICTION] Predicted fire time for file: /Users/jonathanhirsch/Movies/Torrent Series/Dexter/Season 3/Dexter - S03E01.mkv and rule Go into Folders: 5828963-12-20 08:00:00.000 Should poll: 0
2012-07-17 23:55:24.291 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: displayExtension ==[cd] "torrent" negation: 0 result: 0
2012-07-17 23:55:24.291 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 08:00:00.000
2012-07-17 23:55:24.291 hazelworker[6947] DEBUG: [PREDICTION] Bail out: AND predicate
2012-07-17 23:55:24.291 hazelworker[6947] DEBUG: [PREDICTION] Predicted fire time for file: /Users/jonathanhirsch/Movies/Torrent Series/Dexter/Season 3/Dexter - S03E01.mkv and rule Rename Torrents: 5828963-12-20 08:00:00.000 Should poll: 0
2012-07-17 23:55:24.291 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: displayExtension ==[cd] "torrent" negation: 0 result: 0
2012-07-17 23:55:24.291 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 08:00:00.000
2012-07-17 23:55:24.291 hazelworker[6947] DEBUG: [PREDICTION] Bail out: AND predicate
2012-07-17 23:55:24.292 hazelworker[6947] DEBUG: [PREDICTION] Predicted fire time for file: /Users/jonathanhirsch/Movies/Torrent Series/Dexter/Season 3/Dexter - S03E01.mkv and rule Open Torrents: 5828963-12-20 08:00:00.000 Should poll: 0
2012-07-17 23:55:24.293 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: typeObject isType: "public.movie" negation: 0 result: 1
2012-07-17 23:55:24.293 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 08:00:00.000
2012-07-17 23:55:24.293 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: displayBasename hazelContainsObject: "dexter" negation: 0 result: 1
2012-07-17 23:55:24.293 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 08:00:00.000
2012-07-17 23:55:24.385 hazelworker[6947] [Error] Error during rule evaluation: Received error while trying to evaluate rule Copy to Hard Drive on file Dexter - S03E01.mkv
2012-07-17 23:55:24.387 hazelworker[6947] Error while matching rule Copy to Hard Drive against file /Users/jonathanhirsch/Movies/Torrent Series/Dexter/Season 3/Dexter - S03E01.mkv: Error executing AppleScript: {
    NSLocalizedDescription = "Can\U2019t make alias \"Macintosh HD:Users:jonathanhirsch:Movies:Torrent Series:Dexter:Season 3:Dexter - S03E01.mkv\" into type constant.";
    NSLocalizedFailureReason = "Can\U2019t make alias \"Macintosh HD:Users:jonathanhirsch:Movies:Torrent Series:Dexter:Season 3:Dexter - S03E01.mkv\" into type constant.";
    OSAScriptErrorAppAddressKey = "<NSAppleEventDescriptor: [0x0,2 \"hazelworker\"]>";
    OSAScriptErrorAppNameKey = hazelworker;
    OSAScriptErrorBriefMessageKey = "Can\U2019t make alias \"Macintosh HD:Users:jonathanhirsch:Movies:Torrent Series:Dexter:Season 3:Dexter - S03E01.mkv\" into type constant.";
    OSAScriptErrorExpectedTypeKey = "<NSAppleEventDescriptor: 'enum'>";
    OSAScriptErrorMessageKey = "Can\U2019t make alias \"Macintosh HD:Users:jonathanhirsch:Movies:Torrent Series:Dexter:Season 3:Dexter - S03E01.mkv\" into type constant.";
    OSAScriptErrorNumberKey = "-1700";
    OSAScriptErrorOffendingObjectKey = "<NSAppleEventDescriptor: 'alis'(488/360000000001E8000200000C4D6163696E746F7368204844000000000000000000000000000000CBB434C5482B00000136030313446578746572202D205330334530312E6D6B7600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000136030ACBF2FC5E0000000000000000FFFFFFFF0000092000000000000000000000000000000008536561736F6E2033001000080000CBB3C4450000001100080000CBF28BDE0000000100180136030301215A51002C5F0E00044B7200044AAB0000BF11000200614D6163696E746F73682048443A55736572733A006A6F6E617468616E6869727363683A004D6F766965733A00546F7272656E74205365726965733A004465787465723A00536561736F6E20333A00446578746572202D205330334530312E6D6B7600000E002800130044006500780074006500720020002D0020005300300033004500300031002E006D006B0076000F001A000C004D006100630069006E0074006F007300680020004800440012004E55736572732F6A6F6E617468616E6869727363682F4D6F766965732F546F7272656E74205365726965732F4465787465722F536561736F6E20332F446578746572202D205330334530312E6D6B76001300012F00001500020015FFFF000036)>";
    OSAScriptErrorRangeKey = "NSRange: {0, 0}";
}
2012-07-17 23:55:24.388 hazelworker[6947] DEBUG: Tapping error retry sequence
2012-07-17 23:55:24.389 hazelworker[6947] (
   0   CoreFoundation                      0x00007fff93c9bc96 __exceptionPreprocess + 198
   1   libobjc.A.dylib                     0x00007fff91b7c444 objc_exception_throw + 43
   2   CoreFoundation                      0x00007fff93c9ba6c +[NSException raise:format:] + 204
   3   hazelworker                         0x00000001000172c5 start + 89385
   4   Foundation                          0x00007fff9360d3f8 -[NSCustomPredicateOperator performPrimitiveOperationUsingObject:andObject:] + 50
   5   Foundation                          0x00007fff935d416c -[NSPredicateOperator performOperationUsingObject:andObject:] + 116
   6   Foundation                          0x00007fff935d3aed -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 302
   7   Foundation                          0x00007fff935d35e8 -[NSPredicate evaluateWithObject:] + 19
   8   hazelworker                         0x0000000100037f8b start + 223727
   9   hazelworker                         0x0000000100037c90 start + 222964
   10  hazelworker                         0x000000010003d0a7 start + 244491
   11  hazelworker                         0x000000010003752f start + 221075
   12  hazelworker                         0x000000010000278e start + 4594
   13  hazelworker                         0x00000001000036a4 start + 8456
   14  hazelworker                         0x00000001000065cc start + 20528
   15  hazelworker                         0x00000001000015d0 start + 52
   16  ???                                 0x0000000000000003 0x0 + 3
)
2012-07-17 23:55:24.389 hazelworker[6947] DEBUG: [PREDICTION] Predicted fire time for file: /Users/jonathanhirsch/Movies/Torrent Series/Dexter/Season 3/Dexter - S03E01.mkv and rule Copy to Hard Drive: 5828963-12-20 08:00:00.000 Should poll: 0
2012-07-17 23:55:24.392 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: dateAccessed hazelIsInTheLast: 1 Week negation: 1 result: 0
2012-07-17 23:55:24.393 hazelworker[6947] DEBUG: [PREDICTION] Date value: 2012-07-13 06:47:02 +0000 Ref date: 2012-07-17 15:55:24 +0000
2012-07-17 23:55:24.394 hazelworker[6947] DEBUG: [PREDICTION] Handling CUSTOM SELECTOR
2012-07-17 23:55:24.394 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 2012-07-20 14:47:02.939
2012-07-17 23:55:24.394 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: dateAccessed hazelIsEmpty: <null> negation: 1 result: 1
2012-07-17 23:55:24.395 hazelworker[6947] DEBUG: [PREDICTION] Date value: 2012-07-13 06:47:02 +0000 Ref date: 2012-07-17 15:55:24 +0000
2012-07-17 23:55:24.395 hazelworker[6947] DEBUG: [PREDICTION] Handling CUSTOM SELECTOR
2012-07-17 23:55:24.396 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 08:00:00.000
2012-07-17 23:55:24.396 hazelworker[6947] DEBUG: [PREDICTION] Predicted fire time for file: /Users/jonathanhirsch/Movies/Torrent Series/Dexter/Season 3/Dexter - S03E01.mkv and rule Old File: 2012-07-20 14:47:02.939 Should poll: 1
2012-07-17 23:55:24.396 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: dateAccessed >[cd] dateModified negation: 0 result: 1
2012-07-17 23:55:24.400 hazelworker[6947] DEBUG: [PREDICTION] Date value: 2012-07-13 06:47:02 +0000 Ref date: 2012-07-17 15:55:24 +0000
2012-07-17 23:55:24.400 hazelworker[6947] DEBUG: [PREDICTION] Handling GREATER THAN/TRUE
2012-07-17 23:55:24.400 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 08:00:00.000
2012-07-17 23:55:24.401 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: typeObject isType: "public.movie" negation: 0 result: 1
2012-07-17 23:55:24.401 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 08:00:00.000
2012-07-17 23:55:24.401 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: labelColor !=[cd] 1 negation: 0 result: 1
2012-07-17 23:55:24.401 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 08:00:00.000
2012-07-17 23:55:24.402 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: labelColor !=[cd] 0 negation: 0 result: 0
2012-07-17 23:55:24.402 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 08:00:00.000
2012-07-17 23:55:24.402 hazelworker[6947] DEBUG: [PREDICTION] Bail out: AND predicate
2012-07-17 23:55:24.402 hazelworker[6947] DEBUG: [PREDICTION] Bail out: AND predicate
2012-07-17 23:55:24.402 hazelworker[6947] DEBUG: [PREDICTION] Predicted fire time for file: /Users/jonathanhirsch/Movies/Torrent Series/Dexter/Season 3/Dexter - S03E01.mkv and rule Opened: 5828963-12-20 08:00:00.000 Should poll: 0
2012-07-17 23:55:24.402 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: dateModified >[cd] dateAccessed negation: 0 result: 0
2012-07-17 23:55:24.403 hazelworker[6947] DEBUG: [PREDICTION] Date value: 2012-06-10 15:46:54 +0000 Ref date: 2012-07-17 15:55:24 +0000
2012-07-17 23:55:24.403 hazelworker[6947] DEBUG: [PREDICTION] Handling LESS THAN/TRUE or GREATER THAN/FALSE
2012-07-17 23:55:24.403 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 08:00:00.000
2012-07-17 23:55:24.403 hazelworker[6947] DEBUG: [PREDICTION] Bail out: AND predicate
2012-07-17 23:55:24.403 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: labelColor ==[cd] 1 negation: 0 result: 0
2012-07-17 23:55:24.403 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 08:00:00.000
2012-07-17 23:55:24.403 hazelworker[6947] DEBUG: [PREDICTION] Bail out: AND predicate
2012-07-17 23:55:24.403 hazelworker[6947] DEBUG: [PREDICTION] Predicted fire time for file: /Users/jonathanhirsch/Movies/Torrent Series/Dexter/Season 3/Dexter - S03E01.mkv and rule Recently modified: 5828963-12-20 08:00:00.000 Should poll: 0
2012-07-17 23:55:24.403 hazelworker[6947] DEBUG: Dexter - S03E01.mkv: Did not match any rules.
2012-07-17 23:55:24.405 hazelworker[6947] DEBUG: [PREDICTION] Calculating fire time - predicate: labelColor ==[cd] 7 negation: 0 result: 0
2012-07-17 23:55:24.405 hazelworker[6947] DEBUG: [PREDICTION] Next fire time: 5828963-12-20 08:00:00.000
2012-07-17 23:55:24.405 hazelworker[6947] DEBUG: [PREDICTION] Bail out: AND predicate


Thanks!
flynn
 
Posts: 66
Joined: Sun Apr 08, 2012 12:41 pm
Location: Philippines

Re: problem using applescript rule Tue Jul 17, 2012 3:25 pm • by Mr_Noodle
I'm not answering your question directly but instead suggesting an alternative. If you want to copy things file by file and still retain the folder structure, you can have Hazel go into subfolders as described in the sticky article at the top of this forum. In addition to that, use the copy action to copy it to the top level of the destination, then use sort into subfolder, using the "source folder" attribute, which you can use to re-create the folder structure at the destination. Look up "source folder" in the help as there is an example there.
Mr_Noodle
Site Admin
 
Posts: 11291
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: problem using applescript rule Tue Jul 17, 2012 6:55 pm • by flynn
Wow thanks! that worked perfectly!
But I am faced with this new problem: The advantage of my original idea was that the rule only matched if the file didn't exist on my hard drive. How would I go about and make the rule only match if the file is not in my hard drive? Or just make the rule run once per file, even thought I would prefer the first solution in case I delete a file on my hard drive or something by accident and I don't realise it, hazel would just copy the file again.

thanks
flynn
 
Posts: 66
Joined: Sun Apr 08, 2012 12:41 pm
Location: Philippines

Re: problem using applescript rule Wed Jul 18, 2012 1:38 am • by flynn
So I modified the script a little so that it now resembles this:
Code: Select all
set aFile to theFile as alias
set f to path to aFile

set num to get number of characters in f
set num to num - 1
set pathName to characters 51 through num of f as string

set exist to null
set HDf to "Macintosh HD:Volumes:Jono:Series:" & pathName as string
try
   set a to file HDf as alias
   set exist to false
on error
   set exist to true
end try
return exist



and I still get those errors :

Code: Select all
2012-07-18 13:14:58.768 hazelworker[20116] [Error] Error during rule evaluation: Received error while trying to evaluate rule Copy to Hard Drive on file Dexter - S03E01.mkv
2012-07-18 13:14:58.769 hazelworker[20116] Error while matching rule Copy to Hard Drive against file /Users/jonathanhirsch/Movies/Torrent Series/Dexter/Season 3/Dexter - S03E01.mkv: Error executing AppleScript: {
    NSLocalizedDescription = "Can\U2019t make alias \"Macintosh HD:Users:jonathanhirsch:Movies:Torrent Series:Dexter:Season 3:Dexter - S03E01.mkv\" into type constant.";
    NSLocalizedFailureReason = "Can\U2019t make alias \"Macintosh HD:Users:jonathanhirsch:Movies:Torrent Series:Dexter:Season 3:Dexter - S03E01.mkv\" into type constant.";
    OSAScriptErrorAppAddressKey = "<NSAppleEventDescriptor: [0x0,2 \"hazelworker\"]>";
    OSAScriptErrorAppNameKey = hazelworker;
    OSAScriptErrorBriefMessageKey = "Can\U2019t make alias \"Macintosh HD:Users:jonathanhirsch:Movies:Torrent Series:Dexter:Season 3:Dexter - S03E01.mkv\" into type constant.";
    OSAScriptErrorExpectedTypeKey = "<NSAppleEventDescriptor: 'enum'>";
    OSAScriptErrorMessageKey = "Can\U2019t make alias \"Macintosh HD:Users:jonathanhirsch:Movies:Torrent Series:Dexter:Season 3:Dexter - S03E01.mkv\" into type constant.";
    OSAScriptErrorNumberKey = "-1700";
    OSAScriptErrorOffendingObjectKey = "<NSAppleEventDescriptor: 'alis'(488/360000000001E8000200000C4D6163696E746F7368204844000000000000000000000000000000CBB434C5482B00000136030313446578746572202D205330334530312E6D6B7600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000136030ACBF2FC5E0000000000000000FFFFFFFF0000092000000000000000000000000000000008536561736F6E2033001000080000CBB3C4450000001100080000CBF28BDE0000000100180136030301215A51002C5F0E00044B7200044AAB0000BF11000200614D6163696E746F73682048443A55736572733A006A6F6E617468616E6869727363683A004D6F766965733A00546F7272656E74205365726965733A004465787465723A00536561736F6E20333A00446578746572202D205330334530312E6D6B7600000E002800130044006500780074006500720020002D0020005300300033004500300031002E006D006B0076000F001A000C004D006100630069006E0074006F007300680020004800440012004E55736572732F6A6F6E617468616E6869727363682F4D6F766965732F546F7272656E74205365726965732F4465787465722F536561736F6E20332F446578746572202D205330334530312E6D6B76001300012F00001500020015FFFF000036)>";
    OSAScriptErrorRangeKey = "NSRange: {0, 0}";
}
2012-07-18 13:14:58.769 hazelworker[20116] DEBUG: Tapping error retry sequence
2012-07-18 13:14:58.769 hazelworker[20116] (
   0   CoreFoundation                      0x00007fff93c9bc96 __exceptionPreprocess + 198
   1   libobjc.A.dylib                     0x00007fff91b7c444 objc_exception_throw + 43
   2   CoreFoundation                      0x00007fff93c9ba6c +[NSException raise:format:] + 204
   3   hazelworker                         0x00000001000172c5 start + 89385
   4   Foundation                          0x00007fff9360d3f8 -[NSCustomPredicateOperator performPrimitiveOperationUsingObject:andObject:] + 50
   5   Foundation                          0x00007fff935d416c -[NSPredicateOperator performOperationUsingObject:andObject:] + 116
   6   Foundation                          0x00007fff935d3aed -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 302
   7   Foundation                          0x00007fff935d35e8 -[NSPredicate evaluateWithObject:] + 19
   8   hazelworker                         0x0000000100037f8b start + 223727
   9   hazelworker                         0x0000000100037c90 start + 222964
   10  hazelworker                         0x000000010003d0a7 start + 244491
   11  hazelworker                         0x000000010003752f start + 221075
   12  hazelworker                         0x000000010000278e start + 4594
   13  hazelworker                         0x00000001000036a4 start + 8456
   14  hazelworker                         0x00000001000065cc start + 20528
   15  hazelworker                         0x00000001000015d0 start + 52
   16  ???                                 0x0000000000000003 0x0 + 3
)
2012-07-18 13:14:58.770 hazelworker[20116] DEBUG: [PREDICTION] Predicted fire time for file: /Users/jonathanhirsch/Movies/Torrent Series/Dexter/Season 3/Dexter - S03E01.mkv and rule Copy to Hard Drive: 5828963-12-20 08:00:00.000 Should poll: 0


I think the error is coming from
Code: Select all
NSLocalizedDescription = "Can\U2019t make alias \"Macintosh HD:Users:jonathanhirsch:Movies:Torrent Series:Dexter:Season 3:Dexter - S03E01.mkv\" into type constant.";


but I'm not really sure what it means. This works perfectly outside of hazel, so I don't get why when I'm inside hazel I get those errors.
flynn
 
Posts: 66
Joined: Sun Apr 08, 2012 12:41 pm
Location: Philippines

Re: problem using applescript rule Wed Jul 18, 2012 2:05 am • by flynn
Ok so i figured out my problem. Turns out it came from my scripting.
Hazel returns the path of the file, and thus when I was trying to get the path of a path, well, that didn't work out. All I had to do was basically remove the path to part, and my code worked fine.

I'll post it for future references if anyone is interested, with a couple of comments
Code: Select all
set f to theFile as string -- get the path of the matched file

set num to get number of characters in f -- get the number of characters to only keep the end part

set pathName to characters 57 through num of f as string -- remove the path to the torrents series folder. 57 has to be adjusted to match your path to your folder with movies

set exist to null -- an old habbit from java to initialise components, not sure if useful

set HDf to "Macintosh HD:Volumes:Jono:Series:" & pathName as string -- match the path to the one in the hard drive
try
   set a to file HDf as alias --check if an alias can be created
   
   set exist to false -- if it can, then the rule shouldn't match
on error
   set exist to true -- if it can, the rule should match
end try
return exist -- return whether the rule matches or not
flynn
 
Posts: 66
Joined: Sun Apr 08, 2012 12:41 pm
Location: Philippines

Re: problem using applescript rule Thu Aug 02, 2012 8:32 am • by flynn
Well I'm back here because my rules don't seem to always work.
Sometimes, it works perfectly fine, other times it seems like hazel gets "lost" in the process and doesn't sort the file into the subfolder on my hard drive. It ends up copying the file multiple time on my hard drive, I end up with 40 or 50 versions of a file if I leave my hard drive plugged into my computer for a while.

Here is my rule:Image

and here are the two applescript codes I use in my rule:

Code to check if the hard drive exists.
Code: Select all
set ret to null
try
   set a to "Macintosh HD:Volumes:Jono:" as alias
   set ret to true
on error
   set ret to false
end try
return ret



code to check if the file exists in the folder on the hard drive. (Basically the same as the rest of the codes I posted before, just reposting it).
Code: Select all
set f to theFile as string -- get the path of the matched file

set num to get number of characters in f -- get the number of characters to only keep the end part

set pathName to characters 57 through num of f as string -- remove the path to the torrents series folder. 57 has to be adjusted to match your path to your folder with movies

set exist to null -- an old habbit from java to initialise components, not sure if useful

set HDf to "Macintosh HD:Volumes:Jono:Series:" & pathName as string -- match the path to the one in the hard drive
try
   set a to file HDf as alias --check if an alias can be created
   
   set exist to false -- if it can, then the rule shouldn't match
on error
   set exist to true -- if it can, the rule should match
end try
return exist -- return whether the rule matches or not


When a file is not sorted into the subfolders but just left in the hard drive, that's when it copies indefinitely since this rules still matches. When that happens I have to force quit the hazelwork in activity monitor, and delete the files manually or else hazel just keeps on copying and copying but not sorting into the subfolder.

Also, Here are pictures of how my folders are organized:

On my computer: Image

On my hard drive:Image
flynn
 
Posts: 66
Joined: Sun Apr 08, 2012 12:41 pm
Location: Philippines

Re: problem using applescript rule Thu Aug 02, 2012 3:27 pm • by Mr_Noodle
I suggest checking the logs and seeing why it isn't sorting. There should be some sort of error there.
Mr_Noodle
Site Admin
 
Posts: 11291
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: problem using applescript rule Thu Aug 02, 2012 9:41 pm • by flynn
I will try checking the logs, the problem is that it doesn't always happen, and when it does the logs just go on and on by the time I get the console open the logs indicating the sorting are long gone (hazel only has that many logs when my files aren't being sorted). I know why all the other ones aren't being sorted, since it's a duplicate hazel is supposed to delete duplicates but the files are copied faster than hazel seems to be able to respond so they just pile up which is weird seeing as the files take about 1 minute to copy (eventually hazel deletes them, but very slowly). But the reason that the first one is not sorted is still a mystery.

I'll get back once I have the problem again.
flynn
 
Posts: 66
Joined: Sun Apr 08, 2012 12:41 pm
Location: Philippines

Re: problem using applescript rule Fri Aug 03, 2012 12:57 pm • by Mr_Noodle
Do a "Find" for the file that didn't get sorted. That should jump you to the right point in the logs. Note, that it's "Find", not the search field that's built into the window up top.
Mr_Noodle
Site Admin
 
Posts: 11291
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: problem using applescript rule Thu Aug 09, 2012 5:19 am • by flynn
I finally had the problem happen again.

Code: Select all
2012-08-09 17:09:47.265 hazelworker[30957] Could not get Finder item for file: /Users/jonathanhirsch/Movies/External Stuff/Series/Nikita - S02E13.avi
2012-08-09 17:09:47.265 hazelworker[30957] [Error] Copy failed: Could not copy file Nikita - S02E13.avi from folder /Users/jonathanhirsch/Movies/Torrent Series/Nikita/Season 2 to folder /Users/jonathanhirsch/Movies/External Stuff/Series


then duplicates start being created, and I get a bunch of file is busy things.

Code: Select all
2012-08-09 17:12:32.797 hazelworker[31138] File Nikita - S02E13-1.avi is busy. Skipping for now.


and it goes on..

I thought of a way to prevent the duplicates of being created, but that still leaves the problem of the file not sorting.
flynn
 
Posts: 66
Joined: Sun Apr 08, 2012 12:41 pm
Location: Philippines

Re: problem using applescript rule Thu Aug 09, 2012 5:33 pm • by Mr_Noodle
For the busy message you need to find what app has that file open.

For the other error, can you post more of the context around those messages? Like 5-10 lines before and after. It seems Hazel is trying to get/set the comments on that file and can't for some reason which is why I need more context.
Mr_Noodle
Site Admin
 
Posts: 11291
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: problem using applescript rule Thu Aug 09, 2012 8:39 pm • by flynn
Code: Select all
2012-08-09 18:13:28.999 hazelworker[32984] Error copying file from /Users/jonathanhirsch/Movies/Torrent Series/Nikita/Season 2/Nikita - S02E13.avi to /Users/jonathanhirsch/Movies/External Stuff/Series/Nikita - S02E13-1.avi: Error Domain=NSCocoaErrorDomain Code=512 "“Nikita - S02E13.avi” couldn’t be copied to “Series”." UserInfo=0x1092d4dc0 {NSSourceFilePathErrorKey=/Users/jonathanhirsch/Movies/Torrent Series/Nikita/Season 2/Nikita - S02E13.avi, NSUserStringVariant=(
    Copy
), NSDestinationFilePath=/Users/jonathanhirsch/Movies/External Stuff/Series/Nikita - S02E13-1.avi, NSFilePath=/Users/jonathanhirsch/Movies/Torrent Series/Nikita/Season 2/Nikita - S02E13.avi, NSUnderlyingError=0x1092d4c00 "The operation couldn’t be completed. Input/output error"}
2012-08-09 18:13:29.044 hazelworker[32984] [Error] Copy failed: Could not copy file Nikita - S02E13.avi from folder /Users/jonathanhirsch/Movies/Torrent Series/Nikita/Season 2 to folder /Users/jonathanhirsch/Movies/External Stuff/Series


This is as much info as I can get on the file.

For the busy thing, no app is using it. the only open app was the finder and hazel
flynn
 
Posts: 66
Joined: Sun Apr 08, 2012 12:41 pm
Location: Philippines

Re: problem using applescript rule Fri Aug 10, 2012 2:31 pm • by Mr_Noodle
Unfortunately, the underlying error message isn't that descriptive. What happens if you try and copy that file manually? Also, is the destination on some sort of external disk or network share?
Mr_Noodle
Site Admin
 
Posts: 11291
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: problem using applescript rule Fri Aug 10, 2012 9:10 pm • by flynn
The destination is on an external hard drive. It doesn't matter if I copy the file as I have no rules on my hard drive. the sorting part is on the same rule as the copying part, just after.
flynn
 
Posts: 66
Joined: Sun Apr 08, 2012 12:41 pm
Location: Philippines

Re: problem using applescript rule Mon Aug 13, 2012 2:55 pm • by Mr_Noodle
I'm not sure if I follow. Basically, manually do the operations that the rule does and see if it works.

As for busy files, try using the 'lsof' command on the file to see what process has it open. It might not be a GUI program.
Mr_Noodle
Site Admin
 
Posts: 11291
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Next

Return to Support