Finder can't recognise PDF files without .PDF extension

I have a bunch of PDF files (hundreds). They are all named xxx.pdf-yyyyyyyy where yyyyyyyy is some random unique number. If I double click the file in Finder I get the popup "There is no application set to open the document" and asks me to choose an application to open the file with.


If I manually remove the -yyyyyyyy part of the file name so that it ends with ".pdf" it works fine and preview brings the file up.


From the shell, if I use the "file" command on one of these files it recognises the file(1) magic and tells me "PDF document, version 1.5" so this proves that the file format is correct. Besides preview can open the file if I remove the -yyyyyyyy from the filename as explained above.


So my questions are:

Is it possible to get finder to recognise the file based on its "content", file(1) data or some other metadata instead of depending solely on the ".pdf" extension?

MacBook Air, macOS High Sierra (10.13.4)

Posted on Jun 29, 2018 4:17 AM

Reply

Similar questions

2 replies

Jun 29, 2018 4:23 AM in response to Barstuard

BTW: I get about 50 of these posted to me each day. A script to remove the -yyyyyyyy extension is easy to put together but it's not the answer I am after. It works on Linux and even Windows! so why not on the Mac. Maybe someone has an AppleScript to do this? Seems simple enough that Finder should be able to consult the find(1) db as a last resort.

Jun 29, 2018 5:55 AM in response to Barstuard

It doesn't work because neither Linux nor Windows are a UNIX operating systems, which uses a magic database to recognize files by the first couple of bytes (e.g. %PDF) in the file. From a Finder double-click perspective, the operating system maintains a launch control database that keys off the file extension when attempting to open via double-click, or using the Open With sub-menu of applications.


The Finder has no idea what the .pdf-yyyyyyyy string is, and gives you that no application warning. The only work around is to append the -yyyyyyyy info to the basename of the file, and only use the .pdf extension. Once you do that, the launch services database will realize that these are PDF files, and the Finder will allow you to open them in the normal manner.


Rename your PDF files:


sed -En 's/(.*)\.pdf(-.*)$/\1\2\.pdf/p' <<<"xyz.pdf-06292018"


Result:

xyz-06292018.pdf

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Finder can't recognise PDF files without .PDF extension

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.