How to make a plist file

I want my app to be able to continue receiving mailto: Apple events in Mojave and later, and it seems I have to make an info.plist file with an NSAppleEventsUsageDescription key. What tool do I need to make a plist file?

Any app which can edit/create xml files. I would probably use BBEdit. You could also use XCode. You might want to start with the .plist file which Xojo creates when you compile then and the entries you need

What is wrong with Text Edit?

Actually I poked around a bit and used /usr/libexec/plistbuddy and now have a plist file included in my app. Next I guess is to build it and try under Mojave.

I’d recommend Xcode. Free. Handles both binary and plain text plist files. Displays the nodes with their human readable names. Easy to use.

I found plistbuddy a doddle to use. And when I looked at the plist in the Resources folder after the build, mine had been incorporated into it, so that is probably solved.

textedit adds unwanted characters like curly quotes or so. it’s a pain to edit pure text files.
textwrangler is far better and free. and old. or bbedit the free version. or xcode (but it’s so huge to only edit text files)

You can set these things in App Wrapper; version 3.9 (which is still in testing) has specific fields for these new security things. If you want to give it a try, I’ll send you the link.

Long term, that’s probably preferable since I already use AppWrapper. But I think I’ll wait until 3.9 is released: too busy with websocket stuff at the minute.

Plist Class for RealBasic by MacCrafters is an awesome piece of kit for working with plists inside your app. I use it for all sorts of stuff, as I find it much easier than Xojo’s built-in XML stuff.

http://www.pragmaticdesigns.com/plist%202.2.zip

For viewing/editing plists I’m partial to https://www.fatcatsoftware.com/plisteditpro/

“vi” - nuff said!

Just set your edit mode to “Plain Text” (CMD-SHIFT-T). No character substitution and normal LF for EOL.

This isn’t a discussion about one text editor over another. It was about how to create an info.plist file for a specific purpose, given that the Xojo doc said if one added one to the project, it would get merged in at the build stage (which I have observed to be the case). As I have no particular interest in, or knowledge of, plists, or XML, issuing three commands to plistbuddy did the trick nicely for me for the moment.

The Xojo doc also said that I already need to do something for Mojave so my app can handle mailto: via AppleEvents.

If as Sam says AppWrapper will hide that and similar nicely in the near future, then I can open the window and shout Extra! in a loud voice, to be heard only by some crows, the odd pheasant, and a seagull or two. If at night then replace all the former with badgers, unfortunately.

That was meant in total “tongue-in-cheek” mode. I’ve been using one version of “vi” or another since 1982-ish, and even I wouldn’t want to manually generate Plist (or any other XML variant) using it :smiley: .

Here’s some code that can go in a IDE post-build script:

// Sets plist for mac os x build
function SetPlist(key as string, value as string) as string
  // note: CurrentBuildLocation is already escaped
  dim cmd as string =  "defaults write " + CurrentBuildLocation +"/"+ chr(34) +  CurrentBuildAppName + chr(34)+".app/Contents/Info "+ chr(34) + key + chr(34) +  " '" + value + "'"
  dim err as string =  doshellcommand (cmd)
  return err
end function

// Converts plist to text-based XML format (easier to work with)
function ConvertPlistToXML() as string
  // note: CurrentBuildLocation is already escaped
  // convert it XML format for ease of use
  dim cmd as string = "plutil -convert xml1 " + CurrentBuildLocation + "/"+ chr(34) +  CurrentBuildAppName + chr(34)+".app/Contents/Info.plist"
  dim err as string= doshellcommand(cmd)
  return err
end function

// add retina support (not needed with 2018R1 or later)
err = SetPlist("NSHighResolutionCapable", "true") // http://www.realsoftwareblog.com/2012/10/supporting-retina-displays.html
if err <> "" then goto Failed


err = ConvertPlistToXML()
if err <> "" then goto Failed

Success:
return

Failed:
print "FixPlist failed" + EndOfLine + "Err=" + err

Well, plist is just a serialized CFDictionary, so you can use CFDictionaryMBS class in MBS Xojo Plugins.
We even have methods there to convert from/to Xojo dictionary for your convenience.
The XML method there would give you the data for writing to plist file.

And NewCFObjectMBSFromXML(XMLdata as CFBinaryDataMBS) as CFObjectMBS method can be used to read back the XML to read it in. Hm, I may overload that to work with string or folderitem directly…

We even have it more straight forward:

dictionaryWithContentsOfFile(file as folderitem) as CFDictionaryMBS

this reads a file and gives you the CFDictionaryMBS object. Than with Dictionary method you can get it as Xojo dictionary.

Or you have a Xojo dictionary, you can make a CFDictionaryMBS with constructor and use

writeToFile(file as folderitem, useAuxiliaryFile as boolean) as boolean

to write it to disk.