API or other method for accessing Finder icon preview images - bash

It appears that macOS now generates preview images for certain files (notably RAW image files) that are not custom icons but something else. (You can toggle them on/off in latish model macOS via "show icon preview" in Finder window "Show View Options".)
I'd love to be able to either obtain these images or use the API that generates them but I'm obviously googling the wrong terms. The usual APIs will get me the file icon (which is usually a generic document icon) and not the preview. The tricks for getting custom icons (e.g. .DS_Store etc.) do not apply.

The tool you want is qlmanage. In particular, look at qlmanage -t (thumbnail) and qlmanage -p (preview). By default, it opens a viewer for you. If you want to generate files to process yourself, see the -o option. For example:
qlmanage -t image.png -o .
This will create a thumbnail file called ./image.png.png (it attaches .png to whatever the filename is).
If you want to build your own tools around this, see the QuickLook framework.

A little more info w.r.t. using QuickLook framework. The key method is QLThumbnailImageCreate (QuickLook previews are PDFs which are not what I want and likely not what someone doing something similar wants).
Even though the function name indicates that it creates thumbnails, it can create an image of any size (and the size parameter dictates a maximum dimension).

Related

Disable image preview in dialog box

In my Electron app, I am trying to use dialog.showOpenDialog() to allow users to choose the image file that they want to open. On Ubuntu 18.04, when they choose an image file, a preview of the image would appear on the right side like so:
https://i.stack.imgur.com/RG6Po.png
However, if the user chooses a file that is too large (typically 1GB+), my app would crashes, with the following being printed on the command line:
tcmalloc: large alloc 1073741824 bytes == 0x32f584ab4000 # 0x7fb5985b16cf
I tried disable thumbnail generation in the Search & Preview tab of the file manager but it didn't disable this right-hand-side preview in the dialog box.
My app works with very large raster files so being able to choose these image files is crucial. I have considered either installing a new file manager or moving my code to another OS, but I want to ask beforehand if there is any less drastic solution that I can take?
The previews are being added to the GtkFileChooserDialog by Electron itself, so changing your file manager or its settings won't have an effect. Changing OS would work, of course, as drastic as it is.
It does seem like Electron should offer an option for turning off previews among the platform-specific ones in dialog.showOpenDialog. At the minimum, it should enforce a reasonable cutoff on file sizes for previews.
To accomplish that, you'd have to patch Electron locally (and then ideally submit a PR). Whatever you decide to do, I don't see a bug reported about this in the Electron repo, so doing that could be helpful to anyone else who runs into the problem.

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.

Is there a way I can edit or rewrite default Matlab Apps?

Is there a way I can edit or rewrite default Matlab Apps such as "Image Viewer?"
Matlab R2016b
The Image Viewer App is called from the command line as imtool. You can open this file in the Editor using edit like so:
edit imtool
or you can find its location with which and open it in whatever other editor you like:
>> which imtool
C:\Program Files\MATLAB\R2016b\toolbox\images\imuitools\imtool.m
If you really want to modify it, I suggest making a copy of your own and renaming it, leaving the built-in one unchanged and still available.
For other apps, if you go to the "APPS" tab and pull down the menu it will list all the built-in ones available:
Notice that hovering over an app will give a brief description with an associated function name in parentheses. For example, the Video Viewer App can be called with the function implay.

Change icon of running firefox profile

I'm using Win7 but looking for a cross os solution, but this isnt even working in my Win7. I'm trying to change the icon of just the current profile. So what i did was:
I created shortcut of firefox.exe and moved it to my documents
right click on this shortcut and then changed icon
but in firefox the taskbar shows normal firefox icon and so does the top left icon (see attached image plz)
How can I change this icon?
Thanks
Here's another topic i made on ask.m.o trying to ask the same thing: https://ask.mozilla.org/question/725/custom-icon-per-profile/
As of Firefox 57, this is not possible from an extension.
WebExtensions do not permit the window icon to be changed from an extension.
Prior to Firefox 57 (or non-release versions w/ legacy add-ons)
The combination of the title of your question and the text of your question make it unclear what you desire to accomplish.
If your goal is to dynamically change the window icon of a currently running Firefox process then you will need to follow something along the lines of the second or third method listed in nmaier's answer.
If you goal is to always have a different, static icon used for the primary Firefox windows for a specific profile, that is quite easy.
You will need icon files of the appropriate format for each architecture for which you desire this to work.
The following assumes Windows, it is easily expanded to other architectures by including an icon file with the same name, but appropriate file extension and format.
Create a simple overlay, extracted extension. You will need a minimum of 2 files:
<extension-dir>instal.rdf
<extension-dir>\chrome\icons\default\main-window.ico
Example, fully functional, install.rdf:
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>window-icon-change#nowhere.foo</em:id>
<em:version>1.0.0</em:version>
<em:name>Window icon change</em:name>
<em:description>Change the Firefox main window icon.</em:description>
<em:creator>Makyen</em:creator>
<em:unpack>true</em:unpack>
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.0a1</em:minVersion>
<em:maxVersion>43.0a1</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>
NOTE: The "<extension-dir>\chrome\icons\default\" directory is different than the one in the response by nmaier. In that answer the "icons" and "default" directories reversed and will be non-functional.
You will probably want an additional file:
<extension-dir>chrome.manifest
The chrome.manifest file is not required. However, not having it may result in a single line being printed to the error/browser console (if you even have that open). If the chrome.manifest file exists, even if zero length, there will be no complaint in the console that the file could not be read.
Install the extension. The easy way to do this is to create a zip file with those three files; then change the file extension to .xpi; then drag and drop it onto a Firefox window running the profile in which you desire it to be installed.
You can expand this to include icons for whatever sub-windows you desire. You will need to determine the ID for each sub-window. The icon file name is just the window ID with the appropriate extension for an icon in the architectures you desire. "main-window" is just the ID for the main Firefox browser window.
Creating an extension to test this took less than 5 minutes. You should find it reasonably easy to accomplish.
This assumes that there is not a custom main-window icon located at (Windows, default install location):
C:\Program Files\Mozilla Firefox\browser\chrome\icons\default
as that directory is for all profiles and is searched first.
This will not work if the extension is either restartless or extractionless.
You can find a brief amount of information about window icons on MDN. nmaier mentions the docs talking about bundles. When talking about Mozilla add-ons, a bundle is your add-on package.
The icon file(s) will be at (Windows):
<profile dir>\extensions\<extension-dir>\chrome\icons\default*
Once the extension is installed, you can change it/them manually without re-installing, if desired.
Add-ons created to solve this
Based on the discussion in the comments, I created a Firefox Add-on to allow setting the window icons for the profile. It is much expanded upon the 5 minute add-on mentioned in the comments. The addition is entirely in a UI for the options dialog for selecting the icon to use and assigning it to the various different windows Firefox opens. You can get it from Mozilla Add-ons under Change Profile's Window Icons. Unfortunately, it's not possible for that add-on to function as of Firefox 48 which requires add-ons to be signed. To dynamically change the icon requires changing files which must be signed. Thus it's not possible to dynamically change the icon with add-on signing required.
Instead I created a few add-ons which statically change the window icon. You can find them on AMO.
Well, there are some ways that spring to mind, but all with their own issues:
Using Window Icons provided by an add-on you install into the profile (the docs talk about bundles, but add-on can also use this technique). The add-on must be em:unpack and have the icon(s) in chrome/default/icons exactly. It is possible that the Firefox in question has an own set of icons bundled in the $appdir/chrome/default/icons, in particular on *nix and since they are checked first, they will be used instead of the add-on provided add-ons. So while this approach works for custom add-on windows, it might not for built-in ones.
Copy and patch Firefox itself, aka. the sledgehammer approach. Different for each platform (e.g. under Windows you'd have to swap out the icon resource of the firefox.exe).
Create a tool that will switch out the icons of a running window. There is no code to do so in Firefox that would be accessible from javascript, so you need to go binary and platform-specific, e.g. WM_SETICON on Windows.
Edit 1:
Actually, thinking more about it, I'd install an add-on with some platform-specific js-ctypes code that would then switch out the icons, e.g. the already mentioned WM_SETICON on Windows.
Usually you'll need a window handle for the platform APIs, which Firefox refuses to provide to JS. But as a workaround for that:
Store the window title.
Set the window title to a new uuid.
Call a platform API to find the new uuid titled window handle (FindWindow on Windows). mintrayr uses this scheme for Windows/Gnome(GTK/GDK), also not in js-ctypes.
Restore the window title.
Load/transform the icon file to something the platform supports (HICON on windows). I once had a patch somewhere on bugzilla that enabled loading of arbitrary images as window icons FWIW, but let it slide. Should be still somewhere and could give pointers.
Switch the icon using the obtained handle. E.g. Sending two WM_SETICON for small/big icon on Windows.
Edit 2
Turns out nsIBaseWindow exposes a nativeHandle these days, as I learned from your other question. so the window-title–hack isn't needed any longer. However, nativeHandle might be an 64-bit pointer, which isn't really supported in JS land without some trickery... Better not parseInt it... Also js numbers are floats.
ctypes.voidptr_t(ctypes.UInt64(nativeHandle)) should work, though.
On Mac OS X, this Firefox plugin will do just that: https://addons.mozilla.org/en-US/firefox/addon/fosx-label/. Also on GitHub: https://github.com/jf/fosx-label. Thanks to Noitidart for pointing out this very useful plugin.
Tested on Yosemite 10.10.5 and it works perfectly!

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.

Resources