1.0.3 • Published 2 years ago

apple-plist-utils v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Node.js CI Say Thanks!

ApplePlistUtils

ApplePlistUtils is a collection of utilities for working with Apple's plist format.

Installation

npm install apple-plist-utils --save

Sample Plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<!-- Labels are used to uniquely identify jobs when talking to launchd -->
	<key>Label</key>
	<string>com.example.sampled</string>
	<!-- This array of strings maps one-to-one with your main()'s argv -->
	<key>ProgramArguments</key>
	<array>
		<!-- This assumes sampled is in launchd's PATH -->
		<!-- "launchctl getenv PATH" to check the PATH -->
		<string>sampled</string>
	</array>
	<key>MachServices</key>
	<dict>
		<!-- This key maps to what you pass to bootstrap_look_up() -->
		<!-- Always set the value to true. -->
		<key>com.apple.sampled.something</key>
		<true/>
	</dict>
	<key>Sockets</key>
	<dict>
		<!-- This key is completely up to you. -->
		<!-- Use it to differentiate protocols if your code supports more than one. -->
		<key>SampleListeners</key>
		<dict>
			<!-- This dictionary revolves around getaddrinfo(3) -->
			<!-- Please read up on that API, then look at launchd.plist(5). -->
			<!-- Please also make sure your code can deal with more than one FD being allocated. -->
			<key>SockServiceName</key>
			<string>12345</string>
		</dict>
	</dict>
	<!-- This launchd that we will "check in" -->
	<!-- Checking in with launchd is how we get our file descriptors. -->
	<key>ServiceIPC</key>
	<true/>
</dict>
</plist>

Usage

$ cat index.js 
var utils = require('apple-plist-utils')
var file_path = __dirname + '/test.plist'

console.log(JSON.stringify(utils.parseFile(file_path)))

$ node index.js 
{"?xml":{"@_version":"1.0","@_encoding":"UTF-8"},"plist":{"dict":{"key":["Label","ProgramArguments","MachServices","Sockets","ServiceIPC"],"string":"com.example.sampled","array":{"string":"sampled"},"dict":[{"key":"com.apple.sampled.something","true":""},{"key":"SampleListeners","dict":{"key":"SockServiceName","string":12345}}],"true":""},"@_version":"1.0"}}
$ 
$ cat index.js 
var utils = require('apple-plist-utils')
var file_path = __dirname + '/test.plist'

console.log(JSON.stringify(utils.parseFile(file_path)))

$ cat test.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<!-- Labels are used to uniquely identify jobs when talking to launchd -->
	<key>Label</key>
	<string>com.example.sampled</string>
	<!-- This array of strings maps one-to-one with your main()'s argv -->
	<key>ProgramArguments</key>
	<array>
		<!-- This assumes sampled is in launchd's PATH -->
		<!-- "launchctl getenv PATH" to check the PATH -->
		<string>sampled</string>
	</array>
	<key>MachServices</key>
	<dict>
		<!-- This key maps to what you pass to bootstrap_look_up() -->
		<!-- Always set the value to true. -->
		<key>com.apple.sampled.something</key>
		<true/>
	</dict>
	<key>Sockets</key>
	<dict>
		<!-- This key is completely up to you. -->
		<!-- Use it to differentiate protocols if your code supports more than one. -->
		<key>SampleListeners</key>
		<dict>
			<!-- This dictionary revolves around getaddrinfo(3) -->
			<!-- Please read up on that API, then look at launchd.plist(5). -->
			<!-- Please also make sure your code can deal with more than one FD being allocated. -->
			<key>SockServiceName</key>
			<string>12345</string>
		</dict>
	</dict>
	<!-- This launchd that we will "check in" -->
	<!-- Checking in with launchd is how we get our file descriptors. -->
	<key>ServiceIPC</key>
	<true/>
</dict>
</plist>

$ node index.js 
{"?xml":{"@_version":"1.0","@_encoding":"UTF-8"},"plist":{"dict":{"key":["Label","ProgramArguments","MachServices","Sockets","ServiceIPC"],"string":"com.example.sampled","array":{"string":"sampled"},"dict":[{"key":"com.apple.sampled.something","true":""},{"key":"SampleListeners","dict":{"key":"SockServiceName","string":12345}}],"true":""},"@_version":"1.0"}}

License

MIT License
Copyright (c) 2022 by sakaitaka

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago