Tekl Posted July 29, 2016 Posted July 29, 2016 Hi, I would like to create a hotkey for the Finder that opens a selected file in different apps, depending on its filename/path. I tried the filter utility but it does not let any file go through. Even if a filter set to "is not equal to" with an empty value does not execute the connected action. Any ideas? Thanks in advance, Tekl
juliosecco Posted July 29, 2016 Posted July 29, 2016 Hi Teki, I think the best way should be to use a file action. you can define a 'File Action' workflow, that can be used on files reached navigating using Alfred, or on selected files hitting the apposite Alfred Hotkey. you can personalize the hotkey in Alfread Features -> File Search -> Actions, on the bottom of the page. another approach could be to have an hotkey simply launch a workflow with an applescript that retrieves the selected files, but I think the first solution should be better. there is a thread about that http://www.alfredforum.com/topic/2177-use-selected-files-in-finder-for-a-alfred-workflow/ hope is a start for you
deanishe Posted July 29, 2016 Posted July 29, 2016 Hi, I would like to create a hotkey for the Finder that opens a selected file in different apps, depending on its filename/path. I tried the filter utility but it does not let any file go through. Even if a filter set to "is not equal to" with an empty value does not execute the connected action. Any ideas? Thanks in advance, Tekl Can you upload the workflow somewhere so we can have a look at it?
Tekl Posted August 6, 2016 Author Posted August 6, 2016 Hi, thanks for your answers. I don't find a way to upload attachments, so here is a link. Sorry, it can't be downloaded from Safari because I use Tresorit instead of Dropbox. https://tresor.it/s#S2apJh4ALfSDt4_TCaRidA
deanishe Posted August 7, 2016 Posted August 7, 2016 As best I can tell, Selection in OS X and the Filter Utility (and Debug Utility) do not get along if the selection is files, not text. I'll look into it a bit more, but I think it's a bug (or a feature) in Alfred. Fundamentally, I don't think a file selection can work well with a Filter, as the input is a list of strings, not a single string, like you get from other inputs. At any rate, this script will do what you want. Connect your Hotkey to a Run Script Action, set Language to /usr/bin/python and paste the following in the Script box. Remove all other elements. from __future__ import print_function import os from subprocess import check_call, CalledProcessError import sys # Extensions to open with Affinity Photo AP_FILES = ['.pdf', '.psd', '.gif', '.tif', '.afphoto', '.png'] # Extensions to open with TextMate TM_FILES = ['.txt'] def log(s, *args): """Simple STDERR logging.""" if args: s = s % args print(s, file=sys.stderr) # Open matching files with the appropriate application for p in sys.argv[1:]: x = os.path.splitext(p)[1].lower() app = None if x in AP_FILES: app = 'Affinity Photo' elif x in TM_FILES: app = 'TextMate' if not app: log('Ignored : %s', s) continue log('Opening %r with %s ...', p, app) cmd = ['open', '-a', app, p] try: check_call(cmd) except CalledProcessError as err: log('Error opening %r with %s : %r', p, app, err)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now