henrik Posted June 22, 2020 Share Posted June 22, 2020 Hi everyone, I'm already using many text shortcuts that you can set on your Mac or iPhone via System Preferences -> Keyboard -> Text. It's great because it syncs to all of your devices (something Alfred doesn't do since it's not made for phones). However, the shortcuts don't work everywhere (e.g. address bar in Chrome) and they don't have the immediate expansion that Alfred has (you have to press spacebar or select it). Do you think there would be a way to sync the iCloud text shortcuts to a snippet collection? All the best, Henrik Link to comment
deanishe Posted June 22, 2020 Share Posted June 22, 2020 11 minutes ago, henrik said: something Alfred doesn't do since it's not made for phones That's not the reason. It's not possible to build a snippet expansion app for iOS due to the way the system works. 12 minutes ago, henrik said: Do you think there would be a way to sync the iCloud text shortcuts to a snippet collection? It might be possible. Do you know where the system snippets are stored? henrik 1 Link to comment
henrik Posted June 22, 2020 Author Share Posted June 22, 2020 Thanks for the quick reply! 23 minutes ago, deanishe said: It might be possible. Do you know where the system snippets are stored? They are stored under /Users/henrik/Library/KeyboardServices/TextReplacements.db. Does that help? Link to comment
deanishe Posted June 22, 2020 Share Posted June 22, 2020 1 hour ago, henrik said: Does that help? Yup, thanks. Here's a script to sync your macOS text shortcuts to Alfred snippets. henrik 1 Link to comment
henrik Posted June 23, 2020 Author Share Posted June 23, 2020 Thank you so much for this deanishe! I can't get it to work, though.. I'm fairly new to workflows but shouldn't it work like this (when I press the shortcut): Link to comment
deanishe Posted August 21, 2020 Share Posted August 21, 2020 Sorry @henrik, I missed your reply. It isn’t a workflow script, it’s a command-line script (I figured most people would want to run it automatically via a Launch Agent). If you read the post, you’ll see you have to set the SNIPPET_DIR environment variable to the path to your Alfred snippets directory. You can also set SNIPPET_DIR as a workflow variable, but if you don’t set it, the snippets will just be saved in the workflow folder, which is useless. If you're running the script from a workflow, you can probably set SNIPPET_DIR to ../../snippets. Link to comment
paulw Posted December 13, 2020 Share Posted December 13, 2020 @deanishe this is really cool! Do you think it would be feasible to make it a two-way sync by adding Alfred snippets (perhaps only ones with a particular tag) to ~/Library/KeyboardServices/TextReplacements.db with SQLite queries? Link to comment
deanishe Posted December 13, 2020 Share Posted December 13, 2020 3 hours ago, paulw said: Do you think it would be feasible to make it a two-way sync No. Changing the SQLite database is a bad idea: Quote Although Core Data supports SQLite as a store type, the store format—like those of the other native Core Data stores—is private. You cannot create a SQLite database using the native SQLite API and use it directly with Core Data, nor should you manipulate an existing Core Data SQLite store using native SQLite API. paulw 1 Link to comment
dfay Posted December 13, 2020 Share Posted December 13, 2020 I haven't touched this in years but here is how I got my TE snippets into MacOS: https://github.com/derickfay/snipcon-OSX You could use Hazel as I do here but have it output the .plists and import them Link to comment
paulw Posted December 13, 2020 Share Posted December 13, 2020 Thanks, @deanishe. And Thanks, @dfay, I'll look into this option, since I do have Hazel. Link to comment
paulw Posted September 29, 2021 Share Posted September 29, 2021 @deanishe, reviving this thread to ask about your snippets syncing Python script. I have a couple of MacOS keyboard shortcuts that have multi-line text. The script seems to flatten them into a single line. Do you think it would be an easy fix to get the script to respect new lines? Link to comment
deanishe Posted September 30, 2021 Share Posted September 30, 2021 On 9/29/2021 at 2:51 AM, paulw said: Do you think it would be an easy fix to get the script to respect new lines? Fixed. Grab the script again from the same URL. Link to comment
paulw Posted September 30, 2021 Share Posted September 30, 2021 (edited) Thanks! By the way, I did a file comparison between the old and new versions, and you changed export_shortcuts to export_shorcuts. Doesn't seem to be a problem, since it's consistent, but just thought I'd let you know 🤓 Never mind, had that completely backwards. Thanks for your very useful script! Edited September 30, 2021 by paulw Link to comment
andy4222 Posted November 23, 2021 Share Posted November 23, 2021 (edited) On 12/13/2020 at 11:08 AM, paulw said: since I do have Hazel. @paulw Did you get to using hazel to auto sync this when a new snippet is added? Would it be possible to share your hazel rule? I couldn't get it to work EDIT: was also thinking it there's a way to backup existing snippets before overwriting them in alfred Edited November 23, 2021 by andy4222 Link to comment
andy4222 Posted November 26, 2021 Share Posted November 26, 2021 On 9/30/2021 at 12:39 AM, deanishe said: Fixed. Grab the script again from the same URL. Is there a way to get confirmation from the script that it successfully ran so we can post notification about the success or error? Link to comment
deanishe Posted November 26, 2021 Share Posted November 26, 2021 27 minutes ago, andy4222 said: Is there a way to get confirmation from the script that it successfully ran so we can post notification about the success or error? It's a standard POSIX script. If it failed, it exits with a non-zero status, and it logs what it's doing to STDERR. Wire it up however you want. Link to comment
andy4222 Posted November 26, 2021 Share Posted November 26, 2021 21 minutes ago, deanishe said: It's a standard POSIX script. If it failed, it exits with a non-zero status, and it logs what it's doing to STDERR. Wire it up however you want. I tried putting in the invalid directory path and it didn't log an error. How do I fetch/return stderr from the script PS: not a developer, just play with this stuff Link to comment
deanishe Posted November 26, 2021 Share Posted November 26, 2021 1 minute ago, andy4222 said: the invalid directory path What does that mean? A path that isn't your snippets folder or an actually invalid path (illegal name, directory you can't write to, etc.)? The script doesn't care about the former. If it can write to the path you give it, it will. It's your job to make sure it's pointing at your snippets directory. 4 minutes ago, andy4222 said: How do I fetch/return stderr from the script That depends on how you're running the script, which you haven't told us. Link to comment
andy4222 Posted November 26, 2021 Share Posted November 26, 2021 (edited) 7 minutes ago, deanishe said: What does that mean? A path that isn't your snippets folder or an actually invalid path (illegal name, directory you can't write to, etc.)? The script doesn't care about the former. If it can write to the path you give it, it will. It's your job to make sure it's pointing at your snippets directory. That depends on how you're running the script, which you haven't told us. SNIPPET_DIR = '<setting wrong path here' 7 minutes ago, deanishe said: What does that mean? A path that isn't your snippets folder or an actually invalid path (illegal name, directory you can't write to, etc.)? The script doesn't care about the former. If it can write to the path you give it, it will. It's your job to make sure it's pointing at your snippets directory. That depends on how you're running the script, which you haven't told us. My bad. I am using run script for this. Run script is just a copy paste of your script with paths changed to my alfred's snippet directory Edited November 26, 2021 by andy4222 Link to comment
deanishe Posted November 26, 2021 Share Posted November 26, 2021 (edited) 13 minutes ago, andy4222 said: SNIPPET_DIR = '<setting wrong path here' That’s a perfectly valid path. Your workflow directory presumably now contains a directory called <setting wrong path here full of snippets. 13 minutes ago, andy4222 said: Run script is just a copy paste of your script with paths changed to my alfred's snippet directory Then use Alfred's debugger to see what the script is doing, like with any other workflow. Alfred doesn't care if a Run Script fails or not, only whether its output is valid, so if you want your workflow to behave differently if the script fails, you'll need to call the Python script from a bash wrapper or similar. Edited November 26, 2021 by deanishe Link to comment
andy4222 Posted May 22, 2022 Share Posted May 22, 2022 (edited) This code snippet (to sync Apple and Alfred snippets) doesn't seem to be working after python3 upgrade. @deanisheCould you please help us fix this. Edited May 22, 2022 by andy4222 Link to comment
TomBenz Posted June 8, 2022 Share Posted June 8, 2022 On 5/23/2022 at 12:27 AM, andy4222 said: This code snippet (to sync Apple and Alfred snippets) doesn't seem to be working after python3 upgrade. @deanisheCould you please help us fix this. Any update on this? It will be great if workflow file can be posted as well Link to comment
TomBenz Posted June 9, 2022 Share Posted June 9, 2022 On 8/21/2020 at 11:31 PM, deanishe said: Sorry @henrik, I missed your reply. It isn’t a workflow script, it’s a command-line script (I figured most people would want to run it automatically via a Launch Agent). If you read the post, you’ll see you have to set the SNIPPET_DIR environment variable to the path to your Alfred snippets directory. You can also set SNIPPET_DIR as a workflow variable, but if you don’t set it, the snippets will just be saved in the workflow folder, which is useless. If you're running the script from a workflow, you can probably set SNIPPET_DIR to ../../snippets. @deanishe thanks for script to copy macOS text shortcuts to Snippets. How we do set environment variables above? In python code, def export_shortcuts(shortcuts, dirpath): """Save macOS shortcuts to directory as Alfred snippets.""" log('exporting snippets to %r ...', dirpath) if not os.path.exists(dirpath): os.makedirs(dirpath, 0700) what does 0700 means in the line above? Is it possible to use AppleScript instead of Python to achieve this one way sync? 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