Books! Again

Can someone help me with a problem which has been bugging me for years. I have asked all over the web for advice, including Apple obvs, but nobody has come back with a solution. Some people behave like bots and answer a different question which has no bearing on the issue at hand. It concerns (Apple) Books.

For reasons which cannot be explained, Books decided that it was going to hoover up all the PDF files on my iMac, despite Preview always being set as the default app for opening PDF files. This was the case on my 2015 iMac and now the same thing has happened to my other 2020 iMac.

Today I opened Books on my iPhone and the library was engulfed in PDFs, overwhelming the books, which became a few needles in a huge haystack. There are thousands of PDF files on the iMac and it looks like they have populated both iMacs and the iPhone. I don’t know if they are somewhere else too, apart from their Finder location. I do not have enough years left to edit these files individually.

Someone said that I could delete my Books library and it would leave the files in their original position in the iMac, which sounds ideal but there are too many reports of the files being deleted “everywhere” to make me feel comfortable about this; I need all those PDFs for my work.

In Users/Library/Containers there are two folders called Books and two folders called Books Thumbnails. I do not know if this is right but I’m guessing maybe not. Though I see the difference internally, at the first level, is that one Books folder has a CloudKit folder and the other doesn’t.

I need to know how to get ALL PDFs out of my Books library on all devices, without losing the original PDF files and without losing the small collection of book books and audiobooks in my Books library.

and

To know how to stop this from happening again.

I hope you don’t mind me jumping in with a question unrelated to current topics but I am getting desperate. Any advice anyone here can give me which answers these two questions would be sooo welcome.

Thanks

Drew

Sorry I can’t help with a specific answer but my question would be how the PDFs arrived in Books in the first place. I have hundreds of PDFs on my machine yet Books has a total of eight - and I’m sure I had to manually import them.

If you didn’t need the PDFs in their original locations I guess you could search for them (Find Any File) and move them somewhere safe before dumping them from the Books App.

Personally I’d be hesitant to fiddle with anything in the User/Library/Containers/Books folders for fear of terminally breaking the Books app. Who knows what/how Apple sets them up - it’s weird enough having pairs of (seemingly) identically named folders.

If it is any help. Here is where I find documents added to Books.
/Users/<user>/Library/Mobile Documents/iCloud~com~apple~iBooks/Documents

In Terminal you can do
ls -1 Library/Mobile\ Documents/iCloud\~com\~apple\~iBooks/Documents
to list your Books.

Select a pdf file on the Mac and Get Info then set the default app and click on always…this should allow you to reset pdfs to be opened in Preview or Acrobat Reader or whatever you like.

I don’t know if Books references the actual location of the pdfs it’s grabbed or if it copies it to it’s own library…but deleting all of the unwanted pdfs from Books should not delete them from their original location…but I would check first to verify that it does not remove the original by first going to the original location and make a copy of some pdf elsewhere…then going to Books and deleting it from there with the remove everywhere which will get it out of iCloud. Then go back to the original location and see if the pdf is still there.

At worst…you can just drag and drop all of the pdfs from Books to wherever you want to store them then delete from Books.

Once you’ve deleted all of the unwanted pdfs from Books it should sync with iCloud and they’ll disappear from other devices.

Thanks Neil. The PDF default is and has always been Preview, so I have no idea what allows Books to bypass this. I will certainly check that the original is not deleted by running a test as you suggest and I may run a safe boot too before reaching a conclusion. The big problem is needing to delete in large batches. Otherwise I will be at this for weeks and I can foresee me getting to the end of it, only for Books to do it to me again.

Hi Paal

Thanks for this information. Unfortunately I could not find Mobile Documents on that path. A pity as, if that is where the documents reside, I wonder if I could delete them all from this location in big lumps. The Terminal link did show me the list of titles but there’s no way to manipulate them.

You can do this in Terminal

open Library/Mobile\ Documents/iCloud\~com\~apple\~iBooks/Documents

to open the folder in Finder.

You should be able to do this using the Books app on your Mac. First, confirm that the PDFs in Books are not the only copies of the PDFs you wish to keep. They should be in their original homes on the Mac so that the versions in Books are only copies. Assuming you’ve done that, click the PDFs sidebar item in the Books app in the Library section. That should show all the PDFs in Books. Tap the circled ellipsis (…) in the upper right corner of the Books window and select how you want to display the PDF collection. Select a small number of PDFs (20 or so). Now control-click and select the Remove… option. Select ‘Delete everywhere’, and they will be removed from Books. If those operations went quickly, choose a larger group and repeat. Keep doing so until you have deleted your PDFs from Books.

This was a drastic method. You can modify it by creating a new collection of ‘PDFs to Save’ and one of ‘PDFs to Delete,’ adding PDFs to those collections, and deleting from the PDFs to Delete collection. Note that Collections in Books work much like Albums in Photos and Playlists in Music. Items can be members of several Collections; removing an item from a collection does not delete it, deleting an item removes it from everywhere, and removing a download does not remove it from iCloud but only from the Mac.

Finally, figure out why PDFs are automatically shared with Books when opened. On my Mac, I can share a PDF opened in Preview to Books, but I must do that explicitly.

Many thanks Alan

I was unable to delete more than one PDF at a time but I did not know to use Option when removing a batch of PDFs. As it is, the Terminal script which Paal sent allowed me to just grab all of the PDFs and drag them ( about 6k files / 4.4 GB) to a holding pen on my desktop and Books is now back to books and audiobooks which is great. I am so grateful for everyone’s help. Thank you.

Drew

1 Like

If you double click on a pdf and it opens Books and runs the import…something is amiss. I would get a copy of Onyx for whatever version of macOS you’re running and execute it’s cleanup routines…sounds like something is hosed in the LaunchServices or some other database that it will clear.

I think in recent versions of macOS Books stores epub and ibooks files in
~/Library/Containers/com.apple.BKAgentService/Data/Documents/iBooks/Books.
There’s a separate folder inside this, Audiobooks, for audio books, in which each has a subfolder named with some complex hash.
That’s where I find mine. I am not sure about PDF files though, because I have not imported any into Books. A very good thing that it does not auto-import PDF files though (!) because I have over 37K PDF files on my Mac.
I wonder if sometime in the past, the PDF files in question were imported into Books, and then more recently synch to iCloud was turned on so that both old and new Macs now see the same set?

It syncs to iCloud Drive/Books on my Sonoma laptop so if you’re syncing through iCloud that might be the real location. I don’t have that folder in /Library or in ~/Library either…

I dunno…that folder on my laptop only has 20something files in it all with strange names of numberstring.epub. The folder on iCloud Drive named Books…which strangely enough opens just fine with the terminal link given before but if I open iCloud Drive Books isn’t a visible folder…anyways that folder has 170ish files in it including the photography book updates I added to Books in the last week or so. My guess is that somewhere along the line if one is using iCloud to sync Books it got moved to the latter location.

For those that are interested, there are a few folders that you can see in normal way via Finder in Your User/Library/Mobile\ Documents/. On my mac these:

Affinity Publisher
Automator
BBEdit
Desktop
Documents
Downloads
Drafts
iA Writer
Keynote
MindNode
Numbers
Pages
Preview
Script Editor
Shortcuts
TextEdit

But there are a lot of folders that are hidden, you can use wc -l to count:

 ls -1 Library/Mobile\ Documents | wc -l                                
      96

96 folders total.

Try
ls -1 Library/Mobile\ Documents
to list.

1 Like