Search code examples
pythonmacosservicepy2app

Mac OS X app/service and stdin?


I'm debugging a service I'm developing, which basically will open my .app and pass it some data to stdin. But it doesn't seem like it's possible to something like:

open -a myapp.app < foo_in.txt

Is it possible to pass stuff to an .app's stdin at all?

Edit: Sorry, I should have posted this on SO and been more clear. What I'm trying to do is that I have an app made in Python + py2app. I want to be able to handle both when a user drops a file, and use it as a service. The first case isn't a problem since py2app has argv_emulation. I just check if the first argument is a path.

But reading from stdin doesn't work at all, it doesn't read any data regardless if I do as the example above or pipe it. If I pass stdin data to the actual python main script, it works. So I rephrase my question, is it possible to read from stdin with a py2app bundle?


Solution

  • What do you mean with using it as a service?

    The example you show won't work, the open command calls LaunchServices to launch the application, and there is no place in the LaunchServices API to pass stdin data or similar to the application.

    If you mean adding an item to the OS X Services Menu, you should look at the introductory documentation for developers.