OS X document icon missing
Paul Dupuis
paul at researchware.com
Wed Oct 18 11:35:40 EDT 2023
On 10/17/2023 8:11 PM, J. Landman Gay via use-livecode wrote:
> How do I force Finder to show a custom document icon? I've created
> .icns files for both the app and its documents. I entered a custom
> extension in standalone settings. In a built standalone the app icon
> appears normally but an associated stack document has only a generic
> blank icon.
>
> I used Get Info to set the document stacks to always open with my app
> (and it does) but the icon still does not appear. The plist does
> contain the correct icon info and both .icns files are present in the
> app's Contents/Resources/ folder.
>
> It looks like a Finder problem but relaunching Finder didn't fix it.
> Ideas?
>
> LC 9.6.10.
I don't think this is related to the problem (above) you have. If you
have identified the document extension in the Standalone setting for
macOS and set an ics file of icons (or the appropriate sizes required by
Apple) than documents created by that app should display the icon. I'd
double check that the Docunmet extension and Document Type (if you're
using Types) in the setting match what the file is actually using. I've
had an extra character (sometime a space which is hard to see) in the
past that took me a bit to figure it out.
Unrelated, if you ever need more than one document type, below is some
code I run 'on standaloneSaved' to modify the plist to add additional
document types and icon sets to my macOS app.
put tMac64BuildFolder&tAppName&".app/Contents/Info.plist" into
tSrcFile -- overwrite original
--
if there is a file tSrcFile then
put revXMLCreateTreeFromFile(tSrcFile,true,true,false) into tTreeID
if tTreeID begins with "xmlerr" then
answer error "<p>Error reading XML plist file for updating
document types during build.</p><p>"&tTreeID&"</p>"
else
-- list of document types <name>,<icon file><extension>,<type
code><cr>
put "HyperRESEARCH Study,StandaloneDoc.icns,hs2,HRs2"&cr into
tDocTypes
put "HyperRESEARCH Tools,StandaloneTool.icns,rwtl,RWTL"&cr
after tDocTypes
put "HyperRESEARCH Study Package,StandalonePackage.icns,hsz,HSZ
"&cr after tDocTypes
put "HyperRESEARCH Study
Package,StandalonePackage.icns,hs4z,HS4Z" after tDocTypes
-- XML template
put
"<dict>"&cr&"<key>CFBundleTypeExtensions</key>"&cr&"<array>"&cr&"<string>[[tExtension]]</string>"&cr&"</array>"&cr
into tXMLTemplate
put
"<key>CFBundleTypeIconFile</key>"&cr&"<string>[[tIconFile]]</string>"&cr&"<key>CFBundleTypeName</key>"&cr
after tXMLTemplate
put
"<string>[[tDocName]]</string>"&cr&"<key>CFBundleTypeOSTypes</key>"&cr&"<array>"&cr&"<string>[[tTypeCode]]</string>"&cr
after tXMLTemplate
put
"</array>"&cr&"<key>CFBundleTypeRole</key>"&cr&"<string>Editor</string>"&cr&"</dict>"&cr
after tXMLTemplate
-- add document types under parent <plist><dict><array> at end
repeat for each line tDocType in tDocTypes
put item 1 of tDocType into tDocName
put item 2 of tDocType into tIconFile
put item 3 of tDocType into tExtension
put item 4 of tDocType into tTypeCode
put merge(tXMLTemplate) into tNodeContents
revXMLAppend tTreeID, "/plist/dict/array",tNodeContents
end repeat
-- output updated plist
get empty -- clear 'it' for any possible error from revXMLText
that places the error in 'it'
put revXMLText(tTreeID,,true) into tXMLText
if it is not empty then
answer error "<p>Error writing updated XML plist
file.</p><p>"&it&"</p>"
end if
put uniDecode(uniEncode(tXMLText),"UTF8") into URL
("file:"&tSrcFile)
end if
end if
More information about the use-livecode
mailing list