Jump to content

How export snippets as text


Recommended Posts

You can right-click on the snippet collection you are interested in and choose "Export".

 

Then this python3 script should print the details out (change "snippetExportFile" with your exported filename).

 

#!/usr/bin/env python3

from zipfile import ZipFile
import os 
import json

snippetExportFile = '/Users/kpw/Desktop/kpw.alfredsnippets'

with ZipFile(snippetExportFile, 'r') as zip:
    files = zip.filelist
    for zipfile in files:
        if zipfile.filename.endswith(".json"):
            with zip.open(zipfile.filename) as myfile:
                snippetFileJson = myfile.read()
                alfredDict = json.loads(snippetFileJson.decode('utf-8'))
                snippetDict = alfredDict["alfredsnippet"]
                print(f'Name:\t\t{snippetDict["name"]}')
                print(f'Keyword:\t{snippetDict["keyword"]}')
                snippetText = snippetDict["snippet"].replace("\n", "\\n")
                print(f'Snippet:\t{snippetText}')
                print("-" * 80)

 

Link to comment

Hi kpw,

This looks great.

Do I have to download python3 first, I guess-via Homebrew?

Then when I have Python, should I install the script into /usr/bin/env ?

 

Maybe I need to read up on it to get the basic idea?

Sorry, many questions.

/
with best regards,
Omar KN, Stockholm, Sweden

Link to comment
2 hours ago, OmarKN said:

Do I have to download python3 first, I guess-via Homebrew?

 

As soon as you run the command, macOS should offer to install the Developer Tools which will include python3.

 

2 hours ago, OmarKN said:

Then when I have Python, should I install the script into /usr/bin/env ?

 

No, /usr/bin/env is not a directory. Just download the script anywhere and run it with /usr/bin/python3 /PATH/TO/THE/SCRIPT.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...