From 1e17e4a9d18bd918d5e376849d8834f3448ac950 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 30 Nov 2015 18:07:07 +0100 Subject: [PATCH] open folder and select file on osx --- oml/item/api.py | 2 +- oml/utils.py | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/oml/item/api.py b/oml/item/api.py index 70fd75d..1f55b3d 100644 --- a/oml/item/api.py +++ b/oml/item/api.py @@ -339,6 +339,6 @@ def openFolder(data): if item: path = item.get_path() if path: - utils.open_folder(os.path.dirname(path)) + utils.open_folder(path=path) return response actions.register(openFolder, cache=False) diff --git a/oml/utils.py b/oml/utils.py index b2b027e..7dce1ff 100644 --- a/oml/utils.py +++ b/oml/utils.py @@ -331,8 +331,18 @@ def makefolder(path): os.makedirs(dirname) -def open_folder(folder): - cmd = 'open' - if sys.platform.startswith('linux'): - cmd = 'xdg-open' - subprocess.Popen([cmd, folder], close_fds=True) +def open_folder(folder=None, path=None): + cmd = [] + if path and not folder: + folder = os.path.dirname(path) + if folder and not path: + path = folder + if sys.platform == 'darwin': + if folder and not path: + path = folder + cmd += ['open', '-R', path] + elif sys.platform.startswith('linux'): + cmd += ['xdg-open', folder] + else: + logger.debug('unsupported platform %s', sys.platform) + subprocess.Popen(cmd, close_fds=True)