Start TwonkyServer at Boot with launchd in MacOS Sierra

everything about MacOS
Idea
Posts:4
Joined:Wed Feb 08, 2017 2:07 pm
AV Hardware:WeTek Play2
Start TwonkyServer at Boot with launchd in MacOS Sierra

Post by Idea » Wed Feb 08, 2017 2:39 pm

It is possible to start Twonky at boot before a user logs in using launchctl. I have tested Twonky 8.4 with MacOS Sierra 10.12.3 and it works great.

Download the zip file of the current version of Twonky for MacOS. Unzip it and move the folder where ever you like, I moved it to /Applications

Next you'll need to create a launchd plist. Open a terminal and sudo nano /Library/LaunchDaemons/com.twonky.twonkyserver.plist

Here's my plist file. Keep in mind you'll need to change /Applications/twonky-macosx-8.4/twonkyserver to wherever you put your folder and that you need to change my username idea and working directory /Users/idea to match your username:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "–//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.twonky.twonkyserver</string>
        <key>ProgramArguments</key>
        <array>
                <string>/Applications/twonky-macosx-8.4/twonkyserver</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
	<key>KeepAlive</key>
	<true/>
	<key>UserName</key>
	<string>idea</string>
        <key>WorkingDirectory</key>
        <string>/Users/idea</string>
</dict>
</plist>
Press control x and then y and enter to save your plist.

Finally we need to tell the system to load the job:

Code: Select all

sudo launchctl load -w /Library/LaunchDaemons/com.twonky.twonkyserver.plist
In a few seconds you can set up your twonky server normally via the web interface at http://127.0.0.1:9000

To stop twonky and to keep it from loading at boot run:

Code: Select all

[code]sudo launchctl unload -w /Library/LaunchDaemons/com.twonky.twonkyserver.plist
[/code]

If you update twonky and change the path to the program remember to update your plist as well.

One quick note: When I changed to the zip file version of Twonky server I put the .app version in the trash. It seems that removing Twonky.app fires a script to remove twonky's settings. It kept removing /Users/idea/Twonky Library.twonky causing the server to always show as default. After a restart the cleanup script stopped its insanity and I was able to save the server configuration normally.

Hope this helps some folks, cheers.

Post Reply