コード例 #1
0
        if uid_match:
            zettel_id = uid_match.group()
            uid = f"archive.{zettel_id}"
            zettel_date = datetime.strptime(zettel_id, "%Y%m%d%H%M")
            formatted_date = babel.dates.format_datetime(zettel_date, locale='en_US')

        with open(raw_path) as f:
            url = f.readline().strip()

        self["title"] = title
        self["subtitle"] = f"{formatted_date}, {file_title}"
        self["uid"] = uid
        self["match"] = title + " " + file_title
        self["arg"] = f"thearchive://match/{zettel_id}"

alfred.pipeline(
        [
            "ag",
            "--vimgrep",
            '#todo(?![\w-])',
            os.environ["ZETTEL_PATH"],
            ],
        [
            "ag",
            "-v",
            '@done',
            ],
        item_class = Item
        )
コード例 #2
0
class Pass(dict):
    def __init__(self, lines):
        dict.__init__(self)

        item = lines[0]
        value = lines[1]

        self["title"] = value
        self["uid"] = f"com.pass.{item}"
        self["arg"] = item
        self["variables"] = {"line_number": os.environ['line_number']}


long_url = subprocess.run(["./chrome_frontmost_url.js"],
                          capture_output=True).stdout

[_, netloc, _, _, _] = urllib.parse.urlsplit(long_url.decode("utf-8"))

netloc_parts = netloc.split(".")

if len(netloc_parts) > 2:
    netloc_parts = netloc_parts[-2:-1]

netloc = ".".join(netloc_parts)

alfred.pipeline([
    "./pass/pass-usernames.bash",
    netloc,
],
                chunker=alfred.LineChunker(Pass, 2))
コード例 #3
0
pattern_device = re.compile(r'(.*)\((.*)\)')


class Device(dict):
    def __init__(self, lines):
        dict.__init__(self)
        device = lines[0]

        match = pattern_device.match(device)

        if match is None:
            return

        device_name = match.group(1).strip()
        device_type = match.group(2).strip()

        self["title"] = device_name
        self["subtitle"] = device_type
        self["uid"] = f"audio-device.{device_name}.{device_type}"
        self["arg"] = f"-t {device_type} -s '{device_name}'"


devices = sys.stdin.read().splitlines()
items = [Device(d) for d in devices]

alfred.pipeline([
    "SwitchAudioSource",
    "-a",
],
                chunker=alfred.LineChunker(Device, 1))
コード例 #4
0
ファイル: t.py プロジェクト: friedenberg/alfred-preferences
#! /usr/bin/python3

import os
import sys
import re
import pathlib

import alfred
import url_item

alfred.pipeline(
    [
        "./chrome_tabs.js",
    ],
    chunker=alfred.JSONChunker(lambda x: url_item.Item(
        x["title"],
        x["url"],
    ), ),
)
コード例 #5
0
ファイル: zt.py プロジェクト: friedenberg/alfred-preferences
        else:
            self.acc.append(line)

    def is_head_line(self, line):
        return line.startswith('==>') and line.endswith('<==')


alfred.pipeline(
    [
        'find',
        os.path.realpath(os.path.expanduser(os.environ['ZETTEL_PATH'])),
        '-type',
        'f',
        '(',
        '-iname',
        '*.md',
        '-o',
        '-iname',
        '*.txt',
        ')',
        '-print0',
    ],
    [
        'xargs',
        '-0',
        'head',
        '-2',
    ],
    chunker=Chunker(),
)
コード例 #6
0
ファイル: p.py プロジェクト: friedenberg/alfred-preferences
chrome_path = "~/Library/Application Support/Google/Chrome/"
abs_path = os.path.realpath(os.path.expanduser(chrome_path))
base_path = pathlib.Path(abs_path)

paths = [p.absolute().as_posix() for p in base_path.glob('*/Bookmarks')]

alfred.pipeline(
        [
            'jq',
            '.. | .children? | arrays | .[] | select(.type == "url")',
            "--compact-output",
            *paths,
            ],
        [
            "jq",
            "-s",
            ".",
            ],
        #jq --stream "if .[0][-3] == \"children\" and ( .[0][-1] == \"url\" or .[0][-1] == \"name\") then .[1] else null end"
        # [
        #     'osascript',
        #     'chrome_bookmarks.scpt',
        #     ],
        chunker = alfred.JSONChunker(
            lambda x: url_item.Item(
                x["name"],
                x["url"],
                ),
            ),
        )
コード例 #7
0
class Device(dict):
    def __init__(self, device):
        dict.__init__(self)

        if device['connected'] == connected:
            return

        self["title"] = device["name"]

        recentAccessDate = device["recentAccessDate"]

        if recentAccessDate is not None:
            recentAccessDate = iso8601.parse_date(recentAccessDate)
            recentAccessDate = format_timedelta(
                    datetime.now() - recentAccessDate.replace(tzinfo=None),
                    locale='en_US'
                    )
            self["subtitle"] = recentAccessDate + " ago"

        self["uid"] = "bt-device." + device["address"]
        self["arg"] = device["address"]

alfred.pipeline(
        [
            "blueutil",
            f"--{option}",
            "--format=json",
            ],
        chunker = alfred.JSONChunker(Device)
        )