Own file extension - behaviour like picture in OS - image

I'd like to have my own file extension which holds my own data. With double clicking it will start with my own software. So far no problem.
How can i save a picture in that file (metadata?) in a way that it is shown in the OS (Windows, Mac) like a .jpg in the preview window (big symbols in windows, or in the window of the space key preview in macOS)?
The image is generated by my software and therefore is for the user to have a quick info of the internal data...
Thanks in Advance for your help!

Operating systems sometimes allow you to write plugins that read your file data and then convert it to a form that the OS knows how to display in a thumbnail. As for getting your file format to open in existing applications such as Photoshop, this will generally not be possible unless the application developers either choose to add support for your format themselves or allow you to write a plugin, which you will need to do yourself. Most existing file formats that are supported natively in operating systems and user programs have well-known, popular standards and users expect that their software will support these formats by default.

Related

Tell macOS that a custom file format without a .png extension is a valid png

I need a custom file format for my application and I thought that I could make a superset of PNG. macOS shows previews of regular PNG files (and APNGs with a .png extension) in Finder. I want macOS to show a preview of my file format even though it doesn't have a .png extension. I need to tell macOS that files with a .px2 extension are valid PNGs that can be decoded by a regular PNG decoder.
I've been reading this page trying to find the right set of keys to use but I'm not having any luck. I thought that NSExportableTypes might be the answer but that doesn't seem to be it.
To test this, I'm changing the extension of an APNG file from .png to .px2. I realise that I could just use the .png but I think that could be a little confusing (both for the user and the OS).
There's a slight chance that what I'm trying to do is impossible!
I think you may be looking at 2 different problems: one is the OS recognizing the file type and linking it to your application, the other is being able to show the preview.
The latter is going to be highly dependent upon the way that the Finder's in-built QuickLook plugin works. You may need to just implement one of those yourself.
Debugging these kinds of issues can be a little tricky, because you need to make sure macOS has assimilated your NSExportableTypes. One quick check is to drop into Terminal and use mdls <file of your type and extension> and see what the kMDItemContentType and kMDItemContentTypeTree are for your file.
If it's not recognizing the extension at all, make sure it's been re-loaded by using lsregister which is hidden away in the LaunchServices Framework of CoreServices.
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister to get the man page
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -lint -f <path> to force reload of your application (the -lint) adds more detail on errors while interpreting the entries.
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -seed will reset the daemon and re-seed the data from the default applications and library locations.

Get filename/path of the document currently open in another program/window

I'm working on a program that acts as a Windows Accessibility / UI Automation API client, consuming accessibility data from other programs (much like a screen reader does). I'm looking for a way to get the full path of the current "document" (or other file) open in a program. So, for example, Word might give me the path to the current .docx file, Paint the path to the current image file, WMP the path to an audio or video file... you get the idea. Is there a way to do this?
On a Mac, I'd use NSAccessibilityDocumentAttribute, but Windows doesn't seem to have an equivalent accessibility property. A few other questions I looked at:
Getting the path & filename of the open document in any Windows application (last answer in 2009, may have been unaware of accessibility APIs, no answer gives reliably accurate data)
How to get filename and path of file opened in Notepad? - five years old, specific to one program, only answer given is incomplete.
So... is there any equivalent to NSAccessibilityDocumentAttribute, and if not, is there a reasonable way to re-implement it (possibly doing stuff outside of the accessibility tree / API)? It's more important that this return correct information (i.e. never give me a file that isn't open in the relevant program/window) than that it be universally available.
I'm using C# (via System.Windows.Automation for accessibility) but could use other languages if needed, so long as they'll run on Windows 10 (downlevel support nice but not mandatory).

Programmatically determine clipboard source information

When a user copies text to the clipboard, is it possible in Windows to programmatically identify the source file (and/or URL) and text position?
I have looked at a bunch of clipboard management applications (Ditto, clipboardFusion, ArsClip, and ClipDiary) and none appears to record the source of a clip.
It is my belief that this functionality in not possible, but I would like another opinion or two before I abandon my attempts.
I currently think the only way to achieve the desired behavior is to create an add-on / extension for every application that will be copied from. The extension would override the applications normal copy to clipboard behavior with a new format that adds the additional information. The key applications for me would be adobe acrobat (or another pdf reader) and a browser.
Windows does not require any source information to be given when setting clipboard data. Additionally, the only information needed to enable calling that function is a window handle. As such, the best windows could give you in a general case is the window handle that set the clipboard data via GetClipboardOwner.
Some applications set some of the formats on the clipboard to the source location of other data on the clipboard, but again in a general sense, there need not even be any source data; an application can just place random arbitrary data on the clipboard.
For your specific use case, you may be able to write a grease-monkey script to add your meta-data, and as firefox/chrome can display PDFs you might even be able to use the same script for PDFs.

Howto automatically open FITS images and tables with different apps from the Mac OS X Finder?

FITS files can contain several images (or more generally n-dimensional arrays) and tables.
Is there a way to automatically open images e.g. with the ds9 application and tables with the TOPCAT application when I double-click the FITS file in the Mac OS X Finder?
I'm thinking of something like FITS Explorer from AstroSoft, but free and nicely integrated into the Mac (i.e. Finder, Quicklook).
If such a thing doesn't exist, what is your workflow for browsing and opening images and tables in FITS files?
I just found QLFits which is a Mac OS X Finder QuickLook plugin that display some FITS header info and an image simply by hitting SPACE after selecting a FITS file in the Finder.
The same guy wrote FITSImporter:
a Spotlight plugin that allow you make spotlight queries against dedicated FITS header keywords. It provides also additional information in the "Get Info" panel of the Finder (⌘-I).
Both are open source (GPL licence), the code is available on github: QLFITS, FITSImporter.
They are not perfect though (e.g. I didn't see a way to get at the different extensions in a multi-extension FITS file, although the description says there is; and you can't use QLFits to browse tables) and development seems to have stopped, but still well worth a try!
Apart from recommending you QLFits, you could try to write an AppleScript application, or Automator action using any scripting language, which explored the FITS file, and sent table-based FITS to TOPCAT, and image-based FITS to DS9, and make that application the default for FITS files.

How does Windows associate icons to files in explorer shell?

I have both InDesign CS2 and CS3 installed. Both use files with .indd extension. How does Windows know which icon to use? It uses correct icons i.e. CS2 files have cs2 icon and CS3 files have CS3 icon.
How does Windows know how to do this?
And how can I extract or use this version-detection system in my programs?
Edit:
Thank you for your shell-extension-icon-handler answers. Something new to me. But is there any way I could connect to IconHandler that InDesign provides and use it to detect version of the InDesign file?
You need to write an Icon Handler shell extension. See the MSDN documentation for IExtractIcon. The basic mechanism is that you create a shell extension and register the icon handler for the file type you want (look in HKEY_CLASSES_ROOT/.indd) and then the shell loads your handler, passes the file information and requests an icon in return. There's also the IExtractImage method if you want to provide a thumbnail bitmap rather than just an icon.
Note that you need to be especially careful writing shell extension handlers as any memory leaks or crashes can nuke the explorer and any other applications that display a file open/save dialog.
For some files it's HKEY_CLASSES_ROOT\<file extension here>\DefaultIcon registry entry, but most files map to a more friendly name, e.g. .pdf\(Default) -> AcroExch.Document (if Adobe Reader is installed).
In that case you have to go along the registry to AcroExch.Document and see that either
DefaultIcon is right there or
AcroExch.Document\CLSID\(Default) is some GUID. Then, follow HKEY_CLASSES_ROOT\CLSID\<insert that guid here> and you'll notice that this key contains DefaultIcon
... and DefaultIcon is where the icon is loaded from.
Hope that was clear enough ;). I don't know about your special case but there should be a distinction in the registry.
It almost certainly installs a shell icon extension handler. Writing your own and knowing how to detect the version in a file format that isn't documented well or at all is quite tricky.

Resources