An extremely Mac specific question

  • Rune

    Rune - 2007-01-31

    pydev scripting. Is it possible to get the POSIX path of the current document in Eclipse, and then the do a shell command using this?
    (and of course binding this command to a key stroke)

    To clarify a bit, the emacs/lisp equivalent for the operation I want to perform is:
    (defun save-with-transmit () (interactive)
        (start-process-shell-command "save-with-transmit" nil
                                  "osascript" "~/bin/TransmitFile.scpt"
                                    (shell-quote-argument (buffer-file-name))))
    (global-set-key "\C-x\C-t" 'save-with-transmit)

    This code calls the osascript binary on OSX which in turn executes a AppleScript that communicates with to do a sftp upload of a file.


    • Fabio Zadrozny

      Fabio Zadrozny - 2007-01-31

      Yes, should be possible...

      for details on how to bind an action to a keybinding and using the scripting structure, take a look at:

      To get the path from a string in pydev scripting you would do:

      #save editor:
      from org.eclipse.core.runtime import NullProgressMonitor

      #get file complete path:
      from org.python.pydev.core import REF
      f = editor.getEditorFile() <-- returns a (jython)
      print REF.getFileAbsolutePath(f) <-- return full path in filesystem

      and the other things are not actually pydev-dependent (but you should be able to do it in the scripting structure relying on jython without any problems).



    • Rune

      Rune - 2007-01-31

      Hmm..Do I need a jython instalation for this to work?

      - I've added the jython.jar (with Libs) found in org.python.pydev.jython_1.2.6 to Preferences::interpreter jython.
      - I've created a jython2.1 project called pydev_scripts and added its src folder to additional jython scripts.
      - I've created a file in the src folder "" and pasted the code into the file.

      When saving I get this output in the console:
      --->  reloading /Users/roderik/Documents/workspace/pydev_scripts/src/
      Traceback (innermost last):
        File "<string>", line 1, in ?
        File "/Users/roderik/Documents/workspace/pydev_scripts/src/", line 4, in ?
      org.eclipse.swt.SWTException: Invalid thread access
          at org.eclipse.swt.SWT.error(
          at org.eclipse.swt.SWT.error(
          at org.eclipse.swt.SWT.error(
          at org.eclipse.swt.widgets.Widget.error(
          at org.eclipse.swt.widgets.Widget.checkWidget(
          at org.eclipse.swt.custom.StyledText.setEditable(
          at org.eclipse.jface.text.TextViewer.setEditable(
          at org.eclipse.ui.texteditor.AbstractTextEditor.updateState(
          at org.eclipse.ui.texteditor.AbstractTextEditor.doSave(
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(
          at java.lang.reflect.Method.invoke(
          at org.python.core.PyReflectedFunction.__call__(
          at org.python.core.PyMethod.__call__(
          at org.python.core.PyObject.__call__(
          at org.python.core.PyInstance.invoke(
          at org.python.pycode._pyx422.f$0(/Users/roderik/Documents/workspace/pydev_scripts/src/
          at org.python.pycode._pyx422.call_function(/Users/roderik/Documents/workspace/pydev_scripts/src/
          at org.python.core.Py.runCode(
          at org.python.core.Py.exec(
          at org.python.pycode._pyx423.f$0(<string>:1)
          at org.python.pycode._pyx423.call_function(<string>)
          at org.python.core.Py.runCode(
          at org.python.core.Py.exec(
          at org.python.util.PythonInterpreter.exec(
          at org.python.pydev.jython.JythonPlugin.exec(
          at org.python.pydev.jython.JythonPlugin.execAll(
          at org.python.pydev.jython.JythonPlugin.execAll(
          at org.python.pydev.editor.scripting.PyEditScripting.doExec(
          at org.python.pydev.editor.scripting.PyEditScripting.onSave(
          at org.python.pydev.editor.PyEditNotifier$
          at org.python.pydev.editor.PyEditNotifier$

      org.eclipse.swt.SWTException: org.eclipse.swt.SWTException: Invalid thread access

      • Fabio Zadrozny

        Fabio Zadrozny - 2007-01-31

        No, you don't need a jython installation (it will use the jython that comes bundled with pydev in the scripting engine).

        The problem in your case is that your code is executed in a thread... what you want to do is register some action and then put your code in that action (which will be executed in an ui thread)... take a look at the to see how you do that.

        Still, if you wanted to execute something that needed ui access in this thread, you'd can use the code below (you can use it for testing, but it is not the way you should do it in the end...)

        from org.eclipse.swt.widgets import Display #@UnresolvedImport
        from java.lang import Runnable

        def myMethod():
            print 'executing in ui thread'

        class RunInUi(Runnable):
            '''Helper class that implements a Runnable (just so that we
            can pass it to the Java side). It simply calls some callable.
            def __init__(self, c):
                self.callable = c
            def run(self):
                self.callable ()
        def runInUi(callable):
            @param callable: the callable that will be run in the UI

      • Fabio Zadrozny

        Fabio Zadrozny - 2007-01-31
    • Rune

      Rune - 2007-01-31

      Brilliant! Thanks!



Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks