alfred-pass icon indicating copy to clipboard operation
alfred-pass copied to clipboard

alfred-pass not working in macOS Monterey 12.3 onwards

Open burneyy opened this issue 2 years ago • 12 comments

As of macOS Monterey 12.3, python2 (i.e. the binary /usr/bin/python) has been removed from new macOS installations causing the Alfred integration not to work anymore.

Any idea how best to proceed to circumvent that? Migrate the code to python3?

burneyy avatar Mar 25 '22 13:03 burneyy

Hi,

Make sure that you have python3 installed as MacOS 12.3 removed python. (I've installed python3 with brew)

Then replace pass-filter.py script with:

#!/usr/bin/env python3

import fnmatch
import os
import sys
import re
# import string


QUERY = sys.argv[1]
HOME = os.environ['HOME']
PASS_DIR = os.environ.get('PASSWORD_STORE_DIR', os.path.join(HOME, '.password-store/'))


# TODO: list_passwords creates cache of passwords for first time
def list_passwords():
    ret = []

    for root, _, filenames in os.walk(PASS_DIR):
        for filename in fnmatch.filter(filenames, '*.gpg'):
            ret.append(os.path.join(root, filename.replace('.gpg','')).replace(PASS_DIR, ''))
    return sorted(ret, key=lambda s: s.lower())


def search_passwords(query):
    ret = []

    passwords = list_passwords()
    regex = ".*{}.*".format(query)

    for password in passwords:
        if re.match(regex, password):
            ret.append(password)
    return ret


def xmlize_items(items, query):
    items_a = []

    for item in items:
        list = item.split("/", 1)
        name = list[-1]
        path = item if len(list) == 2 else ""

        complete = item
        if item.lower().startswith(query.lower()):
            i = item.find("/", len(query))
            if i != -1:
                complete = item[:(i+1)]

        items_a.append("""
    <item uid="%(item)s" arg="%(item)s" autocomplete="%(complete)s">
        <title>%(name)s</title>
        <subtitle>%(path)s</subtitle>
    </item>
        """ % {'item': item, 'name': name, 'path': path, 'complete': complete})

    return """
<?xml version="1.0"?>
<items>
    %s
</items>
    """ % '\n'.join(items_a)


items = search_passwords(QUERY)
print (xmlize_items(items, QUERY))


(my path for filter script is /Users/XXXXXX/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.08300DF9-3BE9-497B-80AB-D35A7C5E03CC

And in workflow edit pass script filter and change

python pass-filter.py "{query}"

to

/usr/local/bin/python3 pass-filter.py "{query}"

Hope this helps

btaczala avatar Mar 30 '22 19:03 btaczala

@btaczala thanks a lot. Maybe you can make a PR with that?

gi4c0 avatar Apr 07 '22 06:04 gi4c0

PR here: https://github.com/CGenie/alfred-pass/pull/30

btaczala avatar Apr 13 '22 11:04 btaczala

As a heads up, I just updated to Mac OS 12.4 from 11.6 and the above worked, but. my Python was found in /usr/bin/python3, so I needed to edit pass script filter with that location instead of /usr/local/bin/python3.

chipsenkbeil avatar Jun 12 '22 16:06 chipsenkbeil

@chipsenkbeil Added a change to https://github.com/CGenie/alfred-pass/pull/30 to accommodate for that.

emicha avatar Aug 07 '22 10:08 emicha

Applied the change in bfdfaf4942ab66f137bcdf6f38ccabe5cfdfbb01

btaczala avatar Aug 09 '22 12:08 btaczala

After upgrading to mac os 14.0 sonoma my pass workflow stopped working.

with python3 installed via brew the binary was found in /opt/homebrew/bin/python3

I replaced the binary location within the alfred script node and then all was good.

blakecarrasco avatar Oct 23 '23 23:10 blakecarrasco

Hello, thanks for contributing to fixing this. Would someone want to take over the project? I currently don't own a Mac and don't plan to, but it seems this plugin is useful for people.

CGenie avatar Oct 24 '23 05:10 CGenie

Hello, thanks for contributing to fixing this. Would someone want to take over the project? I currently don't own a Mac and don't plan to, but it seems this plugin is useful for people.

Sure, I can take it on. I use it across a series of M1 Macs at this point, both personal and work.

chipsenkbeil avatar Oct 25 '23 18:10 chipsenkbeil

@chipsenkbeil @CGenie Same here, I use pass across my setup, I will be happy to help.

emicha avatar Oct 28 '23 11:10 emicha

@chipsenkbeil @emicha I invited you as collaborators, is this enough?

CGenie avatar Oct 30 '23 13:10 CGenie

@chipsenkbeil @emicha I invited you as collaborators, is this enough?

I accepted it. I can check this weekend to see if some fixes or PRs can be merged in with this access. Maybe @emicha can get to it before I can.

chipsenkbeil avatar Oct 30 '23 19:10 chipsenkbeil