OmarKN Posted May 8, 2023 Share Posted May 8, 2023 Greetings and good day, How to export my snippets as text? So they could be printed out. / with best regards, Omar KN, Stockholm, Sweden Link to comment
kpw Posted May 10, 2023 Share Posted May 10, 2023 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
OmarKN Posted May 10, 2023 Author Share Posted May 10, 2023 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
vitor Posted May 10, 2023 Share Posted May 10, 2023 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. kpw 1 Link to comment
kpw Posted May 10, 2023 Share Posted May 10, 2023 1) homebrew python would be fine. 2) give script executable permission in terminal with “chmod +x scriptfilename.py” 3) can be run from any location with “path-to-script/scriptname.py” vitor 1 Link to comment
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