Run shell script after iTunes has moved file

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

Moderator: Mr_Noodle

Run shell script after iTunes has moved file Thu May 17, 2012 1:44 pm • by deanishe
Hi,

I'm trying to run a post-processing shell script in Hazel after an "Import into iTunes". The shell script never gets run because the action fails as Hazel can't generate an alias for the file (which iTunes has already moved).

The shell script doesn't need the file path anyway, so how can I get Hazel to not try to pass/forget about the file?

Thanks!
deanishe
 
Posts: 5
Joined: Thu May 17, 2012 1:36 pm

Can you post the actual error you are seeing?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Sure.

Code: Select all
2012-05-17 19:21:10.970 hazelworker[63418] The Simpsons 23x21 Ned 'N' Edna's Blend.m4v: Rule Move videos to iTunes matched.
2012-05-17 19:21:22.409 hazelworker[63418] [File Event] File moved: The Simpsons 23x21 Ned 'N' Edna's Blend.m4v moved from folder /Volumes/Users/daj/Temp/Video/Padify to folder /Volumes/Media/iTunes.
2012-05-17 19:21:24.187 hazelworker[63418] /Volumes/Media/iTunes/The Simpsons 23x21 Ned 'N' Edna's Blend.m4v added to iTunes playlist Padify
2012-05-17 19:21:24.188 hazelworker[63418] Hazel Alert: The Simpsons 23x21 Ned 'N' Edna's Blend.m4v added to iTunes
2012-05-17 19:21:24.189 hazelworker[63418] [Custom Message] Hazel Alert: The Simpsons 23x21 Ned 'N' Edna's Blend.m4v added to iTunes
2012-05-17 19:21:24.190 hazelworker[63418] Could not create file alias for path /Volumes/Media/iTunes/The Simpsons 23x21 Ned 'N' Edna's Blend.m4v. Error creating bookmark data: Error Domain=NSCocoaErrorDomain Code=260 "The file couldn’t be opened because it doesn’t exist." UserInfo=0x109986f70 {}
2012-05-17 19:21:24.322 hazelworker[63418] [Error] Shell script failed: Error processing shell script on file /Volumes/Media/iTunes/The Simpsons 23x21 Ned 'N' Edna's Blend.m4v.
2012-05-17 19:21:24.322 hazelworker[63418] Shellscript exited with non-successful status code: 1


As you can see, the file matches a rule, and Hazel (a) moves the file, (b) adds it to iTunes and (c) posts a Growl notification. This is all as it should be. Things go wrong in the next action, which is "run shell script", because Hazel can't find the file it just moved, as iTunes has already renamed and moved it (as a result of the "Add to iTunes" action).

I want to know how to get Hazel to forget about the file (which is gone), and just run a shell script without passing the file path. Even though I don't use $1 in the script, Hazel still tries to generate an alias for the file and blows up.
deanishe
 
Posts: 5
Joined: Thu May 17, 2012 1:36 pm

Well, Hazel can't know that you won't use the passed in file so it has to generate the alias. Can you have the script run before importing into iTunes?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

No, obviously Hazel can't know that I don't need the file. I'm asking if there's a way for me to tell it precisely that. .

Also, I'd argue that Hazel probably should know there's a good chance that any file it runs through its "Import into iTunes" action will immediately disappear, so it won't be able to generate an alias.

No, there's no way I can run the script before importing into iTunes: it's an iTunes script for processing the files after import.
deanishe
 
Posts: 5
Joined: Thu May 17, 2012 1:36 pm

I don't know what you did, Mr Noodle, but it's working splendidly now. Hazel's still logging the can't-make-alias-for-missing-file error, but it's running the script. Great! Thanks very much!
deanishe
 
Posts: 5
Joined: Thu May 17, 2012 1:36 pm

I didn't really do anything. I suspect it's that mysterious bug where shell scripts claimed to be returning a non-zero value but the problem goes away when people either reinstall or reboot.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I figured it out. Hazel is doing its job just fine; my script is throwing an error if a copy was already running (which is most of the time).

I'd read Hazel's logs wrong and got the impression that it wasn't running the shell script because the file had gone. Thanks for your help, and sorry for wasting your time with my dumbness :(
deanishe
 
Posts: 5
Joined: Thu May 17, 2012 1:36 pm


Return to Support