Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3396538
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:25:12+00:00 2026-05-18T04:25:12+00:00

So I have Foo.app , which is configured to run Foo.app/Contents/MacOS/foo.py when it is

  • 0

So I have Foo.app, which is configured to run Foo.app/Contents/MacOS/foo.py when it is launched. In the app’s Info.plist file I also have it set as the application to handle the launching of “.bar” files. When I double-click a .bar file, Foo.app opens as expected.

The problem is that when a file is opened in this way, I can’t figure out how to get the path to the opened file in my foo.py script. I assumed it would be in sys.argv[1], but it’s not. Instead, sys.argv[1] contains a strange string like “-psn_0_2895682”.

Does anyone know how I can get the absolute path to the opened file? I’ve also checked os.environ, but it’s not there either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:25:13+00:00Added an answer on May 18, 2026 at 4:25 am

    You can get your app’s process ID then ask the OS for all open files using lsof, looking for your process’s ID:

    from string import *
    from os import getpid
    from subprocess import check_output, STDOUT
    
    pid = getpid()
    
    lsof = (check_output(['/usr/sbin/lsof', '-p', str(pid)], stderr=STDOUT)).split("\n")
    for line in lsof[1:]:
        print line
    

    The regular files will be of type 'REG' in the fifth column, [4] if you’re indexing in.

    Files open within the running code can be displayed in a similar way:
    from string import *
    from os import getpid
    from subprocess import check_output, STDOUT
    import re

    pid = getpid()
    
    f = open('./trashme.txt', 'w')
    f.write('This is a test\n')
    
    lsof = (check_output(['/usr/sbin/lsof', '-p', str(pid)], stderr=STDOUT)).split("\n")
    print lsof[0]
    for line in lsof[1:]:
        if (re.search('trashme', line)): print line 
    
    f.close
    

    Which results in:

    COMMAND  PID USER   FD   TYPE     DEVICE  SIZE/OFF    NODE NAME
    python  6995 greg    3w   REG       14,2         0 2273252 /Users/greg/Desktop/trashme.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a www.foo.com domain which is setup to load my app on
I have a Rack application that looks like this: class Foo def initialize(app) @app
We currently have a XAP file which contains Foo.dll, and another XAP file (with
I have a app which uses subdomains to route to agencies: foo.domain.dev -> Agency:showAction(foo)
I have an eclipse workspace containing two projects, which I'll call foo-lib and foo-app.
I have a Spring application, which is running on Tomcat say at: http://example.com/foo/ DisplatcherServlet
I have an application in iis available as http://localhost/app/ which means that all relative
I have a small application which can be used to set reminders for future
I have an Android application which handles a particular type of file. It registers
I have a file which contain following lines app.mail.host = 10.1.1.1 app.mail.debug = true

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.