Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tutorial] Installing TraktForVLC on MacOS #75

Closed
Francis2b opened this issue Jul 16, 2017 · 30 comments
Closed

[Tutorial] Installing TraktForVLC on MacOS #75

Francis2b opened this issue Jul 16, 2017 · 30 comments

Comments

@Francis2b
Copy link

Francis2b commented Jul 16, 2017

Hi, @thebluepotato

I need your opinion on my tutorial if nothing is missing maybe @XaF can add it in the ReadMe:

https://francisuniverse.wordpress.com/2017/07/22/install-traktforvlc-on-macos/

@thebluepotato
Copy link

I think it's a very good base to start with, and makes a perfect tutorial. However, this should not be in the README since it's quite "directive" or "conversational" in tone and style, which isn't really the neutral and informative style one aims for in a README.
Your instructions also might be too complete for a basic user's needs. What I mean by this is that the lines I told you to add in the plist for example, they create the logs which not everyone might want or need and the loglevel INFO is for debugging and not really for general usage (we should assume TraktForVLC works and no that it's buggy).
Specifically on what you've written, I think the first step in section 4 isn't necessary since the script runs and replaces the PIN with the tokens even if the first run is with launchctl.
To sum it up : I think your instructions make an excellent tutorial for your website and I think the README should point to this post or your website. However for the README itself, I'll make my own pull request with more succinct directions.

@Francis2b
Copy link
Author

I hope it'll be usefull. When I'll publish the article on my webbsite I'll add a link here if someone want to use my tutorial or a part of it to put in the README go for it I'll be happy if it can help someone

@Lorek162
Copy link

This "Tuto" helped me, because readme instruction for mac are not that great but i'm still having issue with the .plist file not working. I need to manually launch the TraktForVLC.py

@Francis2b
Copy link
Author

Did you check all your directories in your .plist they have to match your installation in order to work?

@Lorek162
Copy link

Lorek162 commented Aug 27, 2017

Yes i don't think this is where is screwed up. My folder is in the "Document" i just replaced my username to "XX" in order to post this here

<?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>org.user.TraktForVLC</string>

<key>ProgramArguments</key>

<array>

<string>/Library/Frameworks/Python.framework/Versions/2.7/bin/python</string>

<string>/Users/XX/Documents/TraktForVLC/TraktClient.py</string>
<string>–loglevel=INFO</string>

</array>

<key>WorkingDirectory</key>

<string>/Users/XX/Documents/TraktForVLC</string>

<key>StandardOutPath</key>

<string>/Users/XX/Documents/TraktForVLC/logs/agentlog.log</string>
<key>StandardErrorPath</key>

<string>/Users/XX/Documents/TraktForVLC/logs/agentlog.log</string>
<key>RunAtLoad</key>

<true/>

<key>LaunchOnlyOnce</key>

<true/>

<key>KeepAlive</key>

<true/>

</dict>

</plist>

@Francis2b
Copy link
Author

Is the directory correct for your python installation

@Lorek162
Copy link

i'm not sure but here's a screen of my /Library/Frameworks/Python.framework/Versions/2.7/bin/ folder
capture d ecran 2017-08-27 a 21 27 18

@Francis2b
Copy link
Author

The directory is ok for your Python.
And did you save your .plist in /Users/YourUserName/Library/LaunchAgents ?

Also, did you restart your computer after?

@Lorek162
Copy link

Yes and Yes :(

@Lorek162
Copy link

Well i restarted my macbook for the 4th time and now it work's .. what the hell, thank's Casper :)

@Francis2b
Copy link
Author

You welcome ;) I'm happy my tutorial helped you! Don't hesitate to let a comment over there if you need more help.

@thebluepotato
Copy link

Being the one who wrote the plist I kinda need to step in here to correct one of my mistakes. The LaunchOnlyOnce doesn't make sure there's only one instance running but prevents the agent from starting more than once per boot. This means that if it crashes for some reason, it won't start again until you restart your computer. Sooooo, I'll have to correct it and I'll make a cute script to install the plist automatically. And also instructions to stop/run the agent without needing to restart your computer.

@Lorek162
Copy link

That's why it didn't show up, i messed up the first time when i made the .plist and when attempting to launch it again it wouldn't. I understand i little bit more but still i've restarted the computer a couple of time at first but probably not after i made the correct .plist i assume. Thank's for the explanation

@Francis2b
Copy link
Author

@thebluepotato Let me know when you do it like that I can update the tutorial ;)

@thebluepotato
Copy link

thebluepotato commented Aug 27, 2017

Basically, copy and paste the following code into a file named install_service_macos.sh (or whatever you like), move that file inside TraktForVLC's directory and run it form Terminal using cd /path/to/TraktForVLC and then ./install_service_macos.sh.

#!/bin/bash

# Stop and unload the service if it's running
launchctl remove org.user.TraktForVLC

# Check if we're running from TraktForVLC's directory
if [ ! -f ./TraktForVLC.py ]; then
    echo "Couldn't locate TraktForVLC.py. Are you running from the right directory?"
    exit 1
fi
traktvlcdir="$(pwd)"

# Check if python is installed
command -v python >/dev/null 2>&1 || { echo >&2 "TraktForVLC requires Python but it couldn't be found. Aborting."; exit 1; }
pythonpath="$(command -v python)"

# Check that no other service called TraktForVLC is already running
if [[ $(launchctl list | grep org.user.TraktForVLC) ]]; then
    echo "TraktForVLC already seems to be running as a service. Please stop it before running this script again."
    exit 1
fi

# Write the plist to LaunchAgents
cat >~/Library/LaunchAgents/org.user.TraktForVLC.plist <<EOL
<?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>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>org.user.TraktForVLC</string>
    <key>ProgramArguments</key>
    <array>
        <string>${pythonpath}</string>
        <string>${traktvlcdir}/TraktForVLC.py</string>
        <string>--loglevel=INFO</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>${traktvlcdir}/logs/agentlog.log</string>
    <key>StandardOutPath</key>
    <string>${traktvlcdir}/logs/agentlog.log</string>
    <key>WorkingDirectory</key>
    <string>${traktvlcdir}</string>
</dict>
</plist>


EOL

# Run the agent
launchctl load ~/Library/LaunchAgents/org.user.TraktForVLC.plist

# Check that it's running
if [[ $(launchctl list | grep org.user.TraktForVLC) ]]; then
    echo "Agent successfully installed and launched!"
else
    cat << EOL
Could not launch agent. The installation might have failed.
Please check that these paths are correct:
Python directory: \`${pythonpath}\`
TraktForVLC directory: \`${traktvlcdir}\`
EOL
fi

If you're unsure about anything I wrote or unfamiliar with Terminal, I'll expand the explanation if needed. The script just does some checks then writes the plist for you with all the correct paths.

Note to those who have already made their own plist: I've slightly changed the name of the plist for uniformity reasons so if you run it, you'll end up with a second plist... Please delete the first one first if you want to run this script.

If you couldn't care less about scripts or thingies, just use this plist and edit accordingly:

<?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>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>org.user.TraktForVLC</string>
    <key>ProgramArguments</key>
    <array>
        <string>/PATH/TO/python</string>
        <string>/PATH/TO/TraktForVLC.py</string>
        <string>--loglevel=INFO</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/PATH/TO/TraktForVLC/logs/agentlog.log</string>
    <key>StandardOutPath</key>
    <string>/PATH/TO/TraktForVLC/logs/agentlog.log</string>
    <key>WorkingDirectory</key>
    <string>/PATH/TO/TraktForVLC/</string>
</dict>
</plist>

Note that the path to python most likely is /usr/bin/python for most uses.

@Lorek162
Copy link

Wow that was fast

"/usr/bin/python" for mac ? when i first looked at this i didn't found the right folder it's only with Casper tutorial that i found my python directory "/Library/Frameworks/Python.framework/Versions/2.7/bin/python"

@thebluepotato
Copy link

@Francis2b
Oh yeah and the script also launches the agent too! Note that in your tutorial as it is, you should remove the step of running TraktForVLC before using launchctl, since launchctl's purpose is to launch TraktForVLC for you and handle everything in the background. If you launch it beforehand, you'll have two instances running or one of them will fail.
Moreover, you should replace launchctl list with launchctl list | grep org.user.TraktForVLC so you'll immediately get the line concerning us if it is running.

@thebluepotato
Copy link

@Lorek162 try running which python in Terminal and you'll see the path your system uses for python when you call it from the command line. For most users it will be /usr/bin/python but it might be different on your setup.

@Francis2b
Copy link
Author

Great might be useful for the next people !
@thebluepotato what's launchctl list | grep org.user.TraktForVLC for?

@Lorek162
Copy link

MacBook-Pro-de-XX:~ XX$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python

is it because macOS is in French ?

@thebluepotato
Copy link

@Francis2b it's for checking if the agent is running. The first part of the command is already mentioned in your tutorial but instead of scrolling through the potentially long and confusing list, the second part of the command catches the line containing the words org.user.TraktForVLC. If it's empty, then the service isn't running.

@Lorek162 Non, mon mac est aussi en français mais j'imagine que tu as un jour installé ta propre version de Python et c'est désormais le chemin utilisé par le système par défaut. Ça marchera tout autant!

@Francis2b
Copy link
Author

@Lorek162 nope my macOS is in English and it's the same path. I think it depends on the python version you're using. One day I read there is a python already installed with macOS, maybe that's why.

@thebluepotato
Copy link

thebluepotato commented Aug 27, 2017

@Francis2b true, it comes with Mac and sometimes some programs require a specific version of Python which, when installed, will overwrite the standard path for the command. Note that the version I'm running with /usr/bin/python is 2.7.10.
But whichever version you're running, you should simply use the path provided by which python, which is basically what the script does using a different command.

@Lorek162
Copy link

" but instead of scrolling through the potentially long and confusing list"
Yes it's a long list i watched it more than 20 times :)

Yeah maybe it's because i first installed python 3.5 and then when it didn't work i installed the 2.7 version as mention in Francis2b's tutorial

@Francis2b
Copy link
Author

Thanks @thebluepotato I updated the tutorial.
By the way do you want me to credit you for the .plist on the tutorial ? I totaly forgot to asked you last time :/

@thebluepotato
Copy link

@Francis2b Meh, if you feel like it, please credit me, but please add a line somewhere that the code is provided as is, without any implicit guarantees, etc., etc. (I'm a lawyer so I cover my back).

@Francis2b
Copy link
Author

Francis2b commented Aug 27, 2017

@thebluepotato yep good idea!

@Francis2b
Copy link
Author

@thebluepotato at the end of the tutorial I added: "(All the above code and files are provided as is, without any implicit guarantees of any kind. If something is not working you can still ask for help in the comments but I'm not a programmer so my knowledge is limited and so is my time 😉)"

@thebluepotato
Copy link

@Francis2b Splendid! Glad I could help

@XaF
Copy link
Owner

XaF commented Apr 16, 2018

TraktForVLC 2.x makes that issue obsolete - #88

@XaF XaF closed this as completed Apr 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants