1

I want to make a Python script to control VLC. VLC can be controlled through AppleScript and by using py-appscript I can run AppleScript code from Python.

Using AppleScript I can play/pause VLC by

tell application "VLC" to play

This equals to the following in py-appscript

app('VLC').play()

I should also be able to skip to next track by:

app('VLC').next()

But when doing so I get the following Python error:

Traceback (most recent call last):
  File "vlclib.py", line 25, in <module>
    app('VLC').next()
TypeError: next() takes exactly 2 arguments (1 given)

Does anyone know why I get this error? The above code should equal the following in AppleScript which works perfectly:

tell application "VLC" to next
TheMaster
  • 45,448
  • 6
  • 62
  • 85
simonbs
  • 7,932
  • 13
  • 69
  • 115
  • Could you post the output of running `help(app('VLC').next)` on line 24 in your script? – jro Oct 24 '11 at 11:55
  • This gives me the following. `Help on method next in module appscript.reference: next(self, klass) method of appscript.reference.Application instance` It is as if it thinks `next()` exists in `py-appscript` but `next()` should call VLC through AppleScript. – simonbs Oct 24 '11 at 12:03

1 Answers1

2

From the appscript documentation:

Names that match Python keywords or names reserved by appscript have an underscore appended.

As next is a reserved keyword, you can fix this by running

app('VLC').next_()
jro
  • 9,300
  • 2
  • 32
  • 37
  • Ah, of course! I guess I didn't think about `next` being a keyword but of course it is. Actually, it is `app('VLC').next_()` – simonbs Oct 24 '11 at 12:17
  • Durr... :). I updated the answer to match the documentation. Thanks! – jro Oct 24 '11 at 12:19