1

I'm trying to run a simple script using launchd in OS X 10.10.5 but the job fails. I think it has something to do with permissions/privileges not set correctly?

This is the error code it throws up:

Traceback (most recent call last): File "/Users/John/Documents/AutoRun/OpenTwitter.py", line 7, in driver = webdriver.Firefox() File "/Library/Python/2.7/site-packages/selenium-3.0.0.b2-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 64, in init self.service = Service(executable_path, firefox_binary=self.options.binary_location) File "/Library/Python/2.7/site-packages/selenium-3.0.0.b2-py2.7.egg/selenium/webdriver/firefox/service.py", line 44, in init log_file = open(log_path, "a+") IOError: [Errno 13] Permission denied: 'geckodriver.log' Exception AttributeError: "'Service' object has no attribute 'log_file'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x10ca6bdd0>> ignored

I do get the printed "start script" in the console job.out that I've hardcoded into my script, so I assume launchd is actually starting the script ok, but it's running into a problem with Selenium/Firefox driver? And this is where my permissions issue is coming into play?

It runs fine in IDE/run and from the terminal.

Here's the test code I'm trying to run:

#!/usr/bin/python

from selenium import webdriver

print("start script")

driver = webdriver.Firefox()
driver.get("https://twitter.com/search?q=news&src=typd&lang=en")


print("twitter open, done")

The P.List as follows:

<?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>JohnsJob.job</string>
    <key>Program</key>
    <string>/Users/John/Documents/AutoRun/OpenTwitter.py</string>
    <key>StandardErrorPath</key>
    <string>/tmp/JohnsJob.job.err</string>
    <key>StandardOutPath</key>
    <string>/tmp/JohnsJob.job.out</string>
    <key>StartCalendarInterval</key>
    <array>
        <dict>
            <key>Hour</key>
            <integer>10</integer>
            <key>Minute</key>
            <integer>14</integer>
            <key>Weekday</key>
            <integer>3</integer>
        </dict>
    </array>
</dict>
</plist>

Note: I change the time for this code to run in launchd so I can test.

11
  • You are precisely correct; the lack of permissions are stopping your script from executing properly. I would suggest you also include the .plist for the launchd in your question too. Commented Aug 24, 2016 at 0:40
  • Thanks for your feedback, I've added the p.list code to the original question, any idea why the permissions are not set correctly and/or how/what file to set them on? Commented Aug 24, 2016 at 0:50
  • Are you launching this as a launchagent or launchdaemon, and which directory is the .plist located? Commented Aug 24, 2016 at 1:02
  • It's located in /Users/John/Library/LaunchAgents - I think it's a "User Agent", that's what it tells me in launchd (I'm new to this so not sure if that's the correct answer) Commented Aug 24, 2016 at 1:04
  • These can be tough to get right the first time and might require trying a few different things. I would start in the .plist and maybe try changing <key>Program</key><string>/Users/John/Documents/AutoRun/OpenTwitter.py</string> to <key>ProgramArguments</key> <array> <string>python</string> <string>/Users/John/Documents/AutoRun/OpenTwitter.py</string> </array> Commented Aug 24, 2016 at 1:34

1 Answer 1

0

I've managed to get it to work by putting the geckodriver in /usr/bin

  1. Move the file to /usr/bin directory: sudo mv chromedriver /usr/bin
  2. Goto /usr/bin directory and you would need to run something like "chmod a+x geckodriver" to mark it executable.

I think it was having trouble finding the PATH to the driver and stopping the script dead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.