Skip to content

Instantly share code, notes, and snippets.

@omiq
Created May 31, 2018 22:41
Show Gist options
  • Select an option

  • Save omiq/9afb585a4c099b235937b586c9dbf96c to your computer and use it in GitHub Desktop.

Select an option

Save omiq/9afb585a4c099b235937b586c9dbf96c to your computer and use it in GitHub Desktop.
Example of selecting files in the filemanager of mac, windows and linux
import sys
import subprocess
def select_file(path):
if sys.platform == 'darwin':
subprocess.run(['open', '-R', path])
elif sys.platform == 'linux':
subprocess.run(['nautilus', path])
else:
command = 'C:\\windows\\explorer /select,"{}"'.format(path)
print(command)
subprocess.run([command])
print("{}: {}".format(sys.platform, path))
file = '/home/chrisg/Pictures/Qt_logo_2016.svg.png'
select_file(file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment