How to get the icon of a file?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
How to get the icon of a file?
Hi all,
is there a way to to get the default file icon displayed in the Finder/Explorer for the file type?
An app i'm working on will allow the user to import files (to be stored as blobs in a db) but it would be really nice to display the default icon for the filetype for the platform... Grateful for any suggestions,
Stam
is there a way to to get the default file icon displayed in the Finder/Explorer for the file type?
An app i'm working on will allow the user to import files (to be stored as blobs in a db) but it would be really nice to display the default icon for the filetype for the platform... Grateful for any suggestions,
Stam
Re: How to get the icon of a file?
If you're looking for the system icons, try
OTOH if you're looking for individual application icons you'll need to look in each application's bundle, i.e.:
Code: Select all
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/
Code: Select all
Applications/LiveCode.app/Contents/Resources/LiveCode.icns
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: How to get the icon of a file?
Thanks @mwieder - was really wondering if there is some library to do this.
I'm looking for file icons of various apps as shown in t he finder/desktop (ie the default powerpoint file icon, pdf file icon etc).
To put things in context this is to move one of my filemaker pro apps to LC; in the FMP app I've set up import of files and FMP shows the file icon in the container field, but not sure how to replicate this in LC, if that's even possible, and especially for cross-platform apps.
So i was wondering if someone else had already done this and whether maybe there was a library for this?
I'm looking for file icons of various apps as shown in t he finder/desktop (ie the default powerpoint file icon, pdf file icon etc).
To put things in context this is to move one of my filemaker pro apps to LC; in the FMP app I've set up import of files and FMP shows the file icon in the container field, but not sure how to replicate this in LC, if that's even possible, and especially for cross-platform apps.
So i was wondering if someone else had already done this and whether maybe there was a library for this?
Re: How to get the icon of a file?
It appears this thread ended here, back in 2021. But I too would like to know if there is an LC library to pull up the Finder icon of a given file (on MacOS or on any other desktop OS). Has this question been explore elsewhere that I am not aware of?
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)
Re: How to get the icon of a file?
Sadly I got no further - and the lack of responses belies the fact that this is not something anyone else could answer at the time.
In the end I created custom SVG icons for the commonest filetypes and a generic icon for 'unknown' filetypes.
Not great really, but did the job more or less.
I know Zax managed something like this, show in his app here: https://forums.livecode.com/viewtopic.php?f=143&t=38966
however if I understood correctly this is MacOS only. And you'll see I raised an issue about image quality as icons were 32 x 32 px (I guess ok for really small icons...)
If this fulfils your brief then DM him and see if he can help - but if like me you need cross-platform support it probably won't suffice.
I sadly have seen nothing equivalent for Windows, although it must be possible...
Stam
In the end I created custom SVG icons for the commonest filetypes and a generic icon for 'unknown' filetypes.
Not great really, but did the job more or less.
I know Zax managed something like this, show in his app here: https://forums.livecode.com/viewtopic.php?f=143&t=38966
however if I understood correctly this is MacOS only. And you'll see I raised an issue about image quality as icons were 32 x 32 px (I guess ok for really small icons...)
If this fulfils your brief then DM him and see if he can help - but if like me you need cross-platform support it probably won't suffice.
I sadly have seen nothing equivalent for Windows, although it must be possible...
Stam
Re: How to get the icon of a file?
Thanks for the update Stam. I would assume the same, namely that it is not functionality that exists, but I will look into your link to what Zax managed to do. It might be ok for me as I'm building for MacOS only at the moment. Your custom icons might work for some better visuals in the meantime. Thanks, mbossiere
“You do what you do out of your own private passion for the thing itself”
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)
A Dillard (source: https://educheer.com/essays/annie-dillard-s-handed-my-own-life/)
Re: How to get the icon of a file?
I wrote an little external for my app for MacOS only.
I'm a complete noob in objective-, foundation and this kind of stuff but I still managed, by copying and pasting bits of code found mainly in the work of Trevor DeVore.
I can of course share this code if anyone here is interested.
The main usages are:
It works for file, folder and applications.
I'm a complete noob in objective-, foundation and this kind of stuff but I still managed, by copying and pasting bits of code found mainly in the work of Trevor DeVore.
I can of course share this code if anyone here is interested.
The main usages are:
Code: Select all
FileGetIcon(pFilePath, pIconSize [, pOptionalOutputFilePath]) // returns image data, or empty, or error string
pIconSize: 32 || 64 || 128 || 512
returns string beginning with "Error :" if an error occurs
example #1: put FileGetIcon("/Applications/Mail.app", 64, "") into image "MyImg" // returns image data
example #2:
get FileGetIcon("/Applications", 128, "path/pOutputFileName.png") // create .png file : icon of folder "Applications"
if word 1 of it is "Error" then answer error it with "Cancel"
Re: How to get the icon of a file?
Thanks Zax... the question at hand is slightly different:It's about getting the icons for filetypes as designated by the current system.
I guess if dragging/dropping a file, this could be used? if it's only for apps then no so much...
In my case ideally would be MacOS+Win but that's a bigger ask...
Stam
I guess if dragging/dropping a file, this could be used? if it's only for apps then no so much...
In my case ideally would be MacOS+Win but that's a bigger ask...
Stam
Re: How to get the icon of a file?
My external works for files, folders and applications.
When starting my project, I found another way to create .png icon file but it only works for appllication with bundle.
Then you will have to convert icns to png using SIPS (Scriptable image processing system) on MacOS X
See https://www.simplehelp.net/2010/10/08/h ... s-in-os-x/
Concerning Windows, I really don't know how to proceed at this time but I would be very interested to make my external run on Windows!
When starting my project, I found another way to create .png icon file but it only works for appllication with bundle.
Code: Select all
--------- tries to read the name of the default icon from the bundle's plist file
put quote & pFileName & "/contents/info" & quote into theFile -- ".plist" extension on "info.plist" isn't needed.
try
put shell("defaults read " & theFile & " CFBundleIconFile") into iconName
if (last char of iconName is cr) then delete last char of iconName
if (debug) then echoMsg "iconName=" & iconName & "---"
if (not iconName contains ".icns") then put ".icns" after iconName -- plist key sometimes don't includes extension
put resPath & iconName into iconPathname
catch errStr
...
end try
Then you will have to convert icns to png using SIPS (Scriptable image processing system) on MacOS X
See https://www.simplehelp.net/2010/10/08/h ... s-in-os-x/
Concerning Windows, I really don't know how to proceed at this time but I would be very interested to make my external run on Windows!