Jump to content

Question - get file icons?

Recommended Posts

Hey all,


I wonder if anyone knows a way to get the icon of a specific file on the local system. Shell script, applescript, whatever, I'm interested. From my googling, I've found plenty of explanations of how to get the icon of an app (pretty obvious really — it's in the bundle), or to specify an icon for various tasks, but I'd really like to be able to retrieve whatever icon the Finder displays for any file to use in my workflow script. Even a generic one (jpg, pdf, etc.) would do.


BTW, if I just refer to the file itself in the "icon" field of Alfred's XML, it does sort of work, but it shows a really shrunk-down "quick-look" icon, not a proper icon, and it's really fugly. And folders don't have anything.


If I can't find something, I'm just going to embed a limited set of generic file-type icons and have them show up for general file types. This will probably be quite tedious, so it'd be great to know if there's a better way before I head down that path.


Thanks in advance for any suggestions.



Link to comment

Alfred actually makes this quite easy for you, you can add a type parameter to the <icon> part of the XML to show file types e.g.


<icon type="filetype">public.jpeg</icon>


...to show the icon for the UTI. If you want the actual icon for the file, you can use e.g.


<icon type="fileicon">~/Desktop</icon> 


...to get the actual icon used for the given path.

Link to comment
I think you can just give it the path of the application. Of course, it wouldn't work if the application was moved or renamed. Not sure if there's a way around that.


I'm thinking specifically about preparing workflows for distribution. For non-Apple software, they might be installed in /Applications or ~/Applications (or anywhere, really).


Being able to use something like <icon type="bundleicon">com.example.Foo</icon> would be useful in that case.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...