I would like to run a few small and simple python scripts for QGIS (Mac) from "outside" of QGIS. With outside I mean in this context, either the normal os command line (terminal.app) or even better, directly out of Sublime Text (text-editor), but definitely not via the inbuilt QGIS python console. I've read through various tutorial e.g. http://www.qgis.org/pyqgis-cookbook/intro.html#python-applications and I am able to get a reference to the QGIS app, but unfortunately not to
qgis.utils.iface or something else deeper. This little code snippet should for instance print out the name of the active layer ... here is what I have:
import sys sys.path.append("/Applications/QGIS.app/Contents/Resources/python") from qgis.core import * import qgis.utils print "helo" # console output: helo QgsApplication.setPrefixPath("/Applications/QGIS.app/", True) QgsApplication.initQgis() print QgsApplication # console output: <class 'qgis.core.QgsApplication'> print qgis.utils.iface # = console output: none aLayer = qgis.utils.iface.activeLayer() print aLayer.name() QgsApplication.exitQgis()
Please don't reply me now how to create a plugin or something else "heavy". I am just looking for a quick an easy way to shoot scripts out of a comfortable text-editor to QGIS. Many thanks!