Note that there are some explanatory texts on larger screens.

plurals
  1. POProgramatically determine .icns file for active application (OSX)
    text
    copied!<p>Question Summary:</p> <p>1) how can i get the path to the currently active application under OSX? (ie the application that owns the current key window)</p> <p>2) from that, i need to determine the normally associated .icns file for that application (ie the image that finder shows when you look at that application in the "Applications" folder, and in the application list that appears when you press command(apple) tab key)</p> <p>Detailed Question description:</p> <p>I am developing an OSX utility toolbar (floating window) that needs to display the name and icon image for the current application (eg the application that owns the window that is currently "key".</p> <p>1) I need some way of programatically determining "the path to .app folder" of the application that is currently main &amp; key. This could either by via a notification callback, or something i can poll on a timer and trigger my own callbacks. </p> <p>2) I can see that manually finding .icns files inside the XXX.app/Resources folder is relatively easy, however the problems is there are sometimes more than 1 .icns file in that folder - and I can see no easy way to determine from the filename alone which is the correct icon normally associated with the application - whilst many applications use the same same name as the application (with an icns extension),some don't. </p> <p>safari for example has a completely unrelated name "compass.icns". there must be a file somewhere that tells finder what file to use - or an api call to do this, anyone have any ideas? NSApplication has the applicationIconImage method, which obviously returns the icon for MY application - that's not what i want - as far as i know there is no way of instantiating NSApplication for another application, and it would make no real sense to do this as most methods/properties are things that are private to that application.</p> <p>for what it's worth, i am porting a windows utility to OSX - if I were doing this under windows, i would use GetWindowProcessID(GetForegroundWindow)), and use that to determine the path to the application, and extract the icon from that using LoadIcon</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload