Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have created a mac application which can be open my file extensions.

But when I tested it, I dont get the path of the file requested to open using the application, instead I got the "psn_0_151589".

I checked it for itunes, textedit, xcode and other applications.

Below is my python app sample main code where i process path of the opened file

import sys
import os.path
print("File opened with this app :: ",sys.argv[1])
if(os.path.exists(sys.argv[1]):
  print("valid file :: { do something...}\n")
else:
  print("Invalid file path received :: { do nothing }\n") 

OUTPUT :

File opened with this app :: psn_0_151589
Invalid file path received :: { do nothing }

Hope someone knows how to get the filepath which was opened using any application.

Any help would be greatly appreciated.

share|improve this question
    
If you posted your code it would be easier to understand your question. –  adayzdone Sep 27 '12 at 14:28
    
updated above with the sample code and its output –  ramsey Sep 27 '12 at 15:28

1 Answer 1

Mac OS X application bundles don't receive the files to be opened as command line arguments. As every application usually only has a single instance, this'd restrict opening further files. Instead, it's a message sent when the application is already running. The argument you receive is the process serial number. More information here.


You could alternatively wrap your Python script in an Automator application's Run Shell Script action (#!/usr/bin/python being the "shell"). When you select to pass input as arguments, they'll be made available in argv, see the sample code:

Screenshot

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.