Page 1 of 1

Delete iTunes library entry on deletion of file?

PostPosted: Mon Dec 03, 2018 1:30 pm
by batsonjay
Hi -

I must be missing something; how do I cause Hazel to *remove* an entry from iTunes library when I delete a file?

(This is a useful thing to have, since deleting an iTunes library entry within iTunes no longer provides the ability to delete the file itself. So, having the ability to simply delete the file, and have iTunes updated, is a desired ability.)

Re: Delete iTunes library entry on deletion of file?

PostPosted: Tue Dec 04, 2018 11:34 am
by Mr_Noodle
I believe iTunes should delete the original. I know when I delete files in iTunes, it brings up an alert with the option to throw it in the trash.

Re: Delete iTunes library entry on deletion of file?

PostPosted: Tue Dec 04, 2018 2:03 pm
by batsonjay
Mr_Noodle wrote:I believe iTunes should delete the original. I know when I delete files in iTunes, it brings up an alert with the option to throw it in the trash.


This is because you have iTunes set to manage your files (e.g. you have the option "Keep iTunes Media folder organized" and "Copy files to iTunes Media folder when adding to library" are both checked.)

If a user does NOT use iTunes to manage the library, iTunes will not offer to delete the file. Many users must choose this option when their audio library grows large, and it becomes necessary to store media on an external storage device. In this case, deleting a song in iTunes deletes the library entry in that instance of iTunes, and also deletes it on all devices to which that library syncs, but does not offer to delete the file.

Thus, having the ability to delete an iTunes entry on deletion of a file in a watched folder is highly valuable to those users.

In fact, I can make a case that "in general", providing a mechanism for a rule to fire on file deletion is a valuable function. Consider these use cases:
  • A user may wish to know if a valid, or malicious application attempts to remove a file from a critically-watched folder, and thus set up a notification when a file is deleted from that folder.
  • Tracking deletion date. A user may wish to add a comment containing a date/time stamp to a file that is moved to the trash; this may be a useful item of info if a user wishes to restore a deleted file in the case there are several files with the same name.
  • (The captioned use case for iTunes)
  • (Similar use case for iPhoto)

I acknowledge this complicates the UI a bit, since the entire rule panel makes a presumption about when a rule will be evaluated.

I suggest a phased approach: Handle the iTunes (and maybe iPhoto) use case first, then consider if a larger capability is required.

An iTunes/iPhoto-only feature could be provided by an easter-egg type hack:
- IF the user sets "Kind" is "Music" in the conditions area;
- THEN
1) Add an entry to the file attribute selector in the conditions section (e.g. the one that has "Passes AppleScript"), adding an entry "Removed from folder", with secondary attributes of (only) "Is" and "True"
-- This allows the user to set a second condition "Removed from Folder"; this provides a 2-rule match that will fire when "Kind is Music" and "Removed from folder is true". There is an error condition that must be checked: This rule only makes sense when "All" of the conditions are met. I'll leave it to you to figure out how to handle that.
-- Yes, I realize this makes the attribute selector contents different depending on context; like I said, this is an Easter Egg ;-D)
2) Add an action "Remove from iTunes" (from playlist ("Library", ....)).

Yes, it's a hack; but it's a useful hack, hopefully won't break anything, and is reasonably aligned with the overall UI metaphors.

Re: Delete iTunes library entry on deletion of file?

PostPosted: Wed Dec 05, 2018 11:27 am
by Mr_Noodle
Having rules matching files on removal opens up a whole other slew of issues. It's something I've thought about off and on but there's a bit that needs to be worked out.

Going back a bit, you can have your library on a separate drive and have iTunes still manage it. In iTunes' Advanced preferences, you can set the location of your library, which can be on another drive.

Re: Delete iTunes library entry on deletion of file?

PostPosted: Sat Mar 09, 2019 9:02 am
by batsonjay
Mr_Noodle wrote:Having rules matching files on removal opens up a whole other slew of issues. It's something I've thought about off and on but there's a bit that needs to be worked out.


I hope you will. I've continued to think about this, and continue to wish I could set rules to fire when a file is deleted.

Mr_Noodle wrote:Going back a bit, you can have your library on a separate drive and have iTunes still manage it. In iTunes' Advanced preferences, you can set the location of your library, which can be on another drive.


This is true. However, there are other reasons to not have iTunes manage files. I'm a working DJ, and having iTunes try to out-think me when I'm constantly previewing, organizing, sorting tracks is a major pain. I will decide what I want in iTunes, when, and I don't want iTunes constantly trying to manage my life, though I do want to intentionally put things in iTunes sometimes, because other DJ apps rely on the iTunes database.

The lack of deletion rule support caused me some unintended side effects today. I realized that I had not created a rule to pull a particular folder of music into iTunes. I did so, but just after I created the rule & it started running, I remembered there was a reason I hadn't created the rule: I have a ton of music in that folder I do NOT want in iTunes (because I simply hadn't yet deleted it). Now I've got to go thru a few hundred tracks in iTunes & manually delete them there, TOO, as I delete them from my drive.

I continue to want a the little hack I proposed above, which avoids most of the general case problems.

Re: Delete iTunes library entry on deletion of file?

PostPosted: Tue Oct 29, 2019 10:46 am
by batsonjay
Bump.

As you are thinking about the switch from Pref Pane to Application for Hazel 5, is it possible for you to incorporate the discussion here (having Hazel fire on deletion of a file?

This would still be very useful to me (and I suspect others).

I acknowledge you likely have a lot to do during creation of Hazel 5; but maybe by reminding you now of this potential need, you can think of a way to add it as you re-work the UX for 5.

Re: Delete iTunes library entry on deletion of file?

PostPosted: Tue Oct 29, 2019 10:56 am
by Mr_Noodle
That is totally independent of re-working the UI. It's still under consideration but if anything, re-doing the UI takes away time from doing other things such as this.

Re: Delete iTunes library entry on deletion of file?

PostPosted: Tue Dec 01, 2020 3:52 pm
by batsonjay
Mr_Noodle wrote:That is totally independent of re-working the UI. It's still under consideration but if anything, re-doing the UI takes away time from doing other things such as this.

One year since last remark about this. I ran into another "folder import" situation similar to the one above today, and ... argh, now I'm faced with an hour of un-doing the work Hazel did manually.

The "rule on deletion" method I described above still holds water. Yes, it's not broadly easy for people, but it solves the problem for a narrow use case, and can get you started on experimenting with this.

So, any thoughts on working on this now?

Re: Delete iTunes library entry on deletion of file?

PostPosted: Wed Dec 02, 2020 10:50 am
by Mr_Noodle
I'm not sure this use case is sufficient enough to warrant the huge amount of work involved. Not saying there aren't other possible cases, but this in and of itself doesn't quite cut it.

Also, looking back, I'm still not sure if your reasoning for not having iTunes manage the library is valid. You can have iTunes manage your library on an external drive. I'm doing it now.

Lastly, even if there was a mechanism to have rules match deleted files, you may be disappointed with the actions that would be available to you. A "Remove from iTunes" may not even be there.

Re: Delete iTunes library entry on deletion of file?

PostPosted: Fri Nov 18, 2022 10:01 am
by batsonjay
Just curious if Hazel has changed enough since I made this initial feature request - and/or your thinking about side effects - has changed since then.

I hesitate to say this, but because I manage your library differently than you doesn't make my way right or wrong; it's just that I - as a user - can't do it your way. I'm a DJ who plays 2 hours of music every week. Here's my workflow. You'll see in here why I'm interested in this feature. (I'm sure there are other cases where this feature would be useful; it's just more information for you why I continue to want this feature.)

To meet my DJ needs I add about 2 dozen new tracks / week to my hard drive - not an external drive (that might be something I forget when I'm packing up to play). I also delete a fair bit of music constantly; not all music is "good for the ages". I keep my actual music files organized by where I got them from - Beatport, Traxsource, Bandcamp, xyz "dj music pool" - for historical reasons.

I use a 3rd-party application - Beatport Pro - to manage my library, primarily because it is VERY efficient at allowing me to cruise through my library to create a "crate" of tracks that I want to select from for a given show. Beatport Pro also allows me to tag & organize music effectively as a DJ. That software - like Hazel - will monitor selected folders and "import" the music into its library.

Note that I *delete* music I want to get rid of from that application, too, since deleting it from that library also deletes the music file - wherever it is located. (I note that Beatport Pro creates an *old version* of an iTunes library file, which my DJ software - Traktor - can read / use. Beatport Pro will NOT use / overwrite the current version of the Apple Music library.)

Apple Music doesn't import a track when I download from those places, because I have those sources set up to download to a location other than Downloads. This is what I use Hazel for - to import those files into Apple Music so that I can have them on my iPhone for background listening as I'm training my ear to know how to mix them when playing live.

Given this, when I delete a file using Beatport Pro, I must (remember to) manually delete it from my Apple Music library, too. I only remember this about 1/2 the time (or only have *time* to delete it about 1/2 the time).

It would make my life MUCH better if I could have a Hazel watch for a file to be deleted from a target folder and have the deletion trigger an action to delete that file from the Apple Music Library.

Are you still of the same mind? (BTW - I'd even pay a couple of hundred bucks to have you implement this feature, if that's any motivation.)

Re: Delete iTunes library entry on deletion of file?

PostPosted: Fri Nov 18, 2022 10:55 am
by Mr_Noodle
Monitoring deletions is a tricky feature and as mentioned previously, what you can do in response will be very limited. I'm not ruling it out but it is a low priority given the amount of design and work involved, its effect on the user interface (rules would be quite different) and the use cases that this can solve (not enough or not super compelling).