Convert TextExpander Snippets to iOS/OS X Text Shortcuts
TextExpander Snippets to iOS/OS X Text Shortcuts
Here is something I’ve been working on for quite a while now. I first had the idea for this when I went to Vienna. I was annoyed that Apple still didn’t allow TextExpander to do what I love it to do. Three weeks ago it looked bad for TextExpander already, now, a couple of weeks later, it looks even worse.
Since Mavericks, Text Shortcuts (System Preferences → Keyboard → Text) sync with iOS devices. I started thinking how to automate adding new shortcuts by script. Scripting the UI is, obviously and technically, my least favorite option, but it’s what I ended up doing.
If you are interested in the technical difficulties that I had to overcome, which make this script work the way it does, read on. Otherwise head to the end to download.
How OS X Text Shortcuts Work
When a new Text Shortcut gets added in the System Preference pane Keyboard → Text, OS X does a couple of things.
First it saves a “receipt” of this addition/removal to ~/Library/Mobile Documents/com~apple~TextInput/ in there are a couple of folders. Most important are those with your username. Open that folder and you see UserDictionary with a subfolder. Select the ones with “~” in their name.
Every time you add or remove a new shortcut a zipped plist will be saved here, containing an Epoch timestamp, the shortcut and the phrase (as Apple calls expansions). Some other data is in the plist as well, but the important bits are the ones I just described.
The other important folder is in ~/Library/Dictionaries/CoreDataUbiquitySupport. This folder looks similar. It contains two folders, somewhere you will find a UserDictionary.db file. This is a SQLite database.
When a new shortcut gets added, a new row will be created here. Again Epoch timestamp, shortcut, and phrase are the important pieces.
What Does Not Work
My first guess was to add new “receipt” files to Mobile Documents. I was hoping that OS X would realize there’s a new file, read it and add it to OS X Text Shortcuts, and that this would also transfer new shortcuts to an iOS device. It does not.
Adding new files here with a similar structure does not update the System Preference pane Table View, nor does it make an iOS device recognize the addition.
I started tinkering with SQLite then. The SQLite database in Dictionaries is only used to feed the Table View displayed in System Preferences. Add new rows here with a similar structure, restart System Preferences, and you will see the new shortcut. Editing the database files does not trigger iCloud to sync shortcuts.
At this point I was pretty disappointed and took my least favorite route, UI scripting. I know it’s hacky, I know it’s dirty, I know all that, but scripting the UI lead to a working solution.
Maybe looking a bit more into Mobile Documents would eventually have resulted in a better solution. I weighed the time it would take me to figure this out against the time it takes me to make a first running version. I prefer things to be done.
How This Script Works
PLEASE READ THIS, IT IS IMPORTANT! ALL YOUR EXISTING SHORTCUTS WILL GO POOF!
Open System Preferences → Keyboard → Text
Click the Table View, select all, press backspace. This deletes all existing shortcuts and takes a moment or two.
Turn off TextExpander text expansion. This is important. Otherwise when the script types the phrase, TextExpander would expand the abbreviation.
It will then compile a list of all your TextExpander snippets.
The script will then click +, type out the abbreviation, ⇥ to the next cell, paste the expansion from the clipboard, press return.
After it has completed typing all shortcuts, TextExpander text expansion will be turned back on.
A few things to note:
As the script automates the UI, just sit and watch. It takes about 4:40 minutes to type in about 300 snippets.
The clipboard is used, because this way the expansion can have multiple lines.
This script is smart enough not to process any dynamic snippets. Dynamic snippets use date calculations, Fill-Ins, and any script snippets.
It takes a while for the list of snippets to be compiled. If AppleScript Editor says “Running…” at the bottom, the script is still running.
If you hear an error beep you may have luck running the script again. Sorry this happens sometimes, I couldn’t figure out why.
Set all snippet groups that you don’t want to be added in disallowedGroups. The name must match the snippet group’s name.
If you want to know how many snippets you have, comment out the part where the script starts adding all Text Shortcuts. There is a line
log "Count of abbreviationList: " & (count of abbreviationList)
After I got diagnosed with hyperactivity, I learned how to meditate. I still call it that way, because it makes it easier for people to understand what I’m doing, when I hide in the closet for 15 minutes. What I really do is known as PMR, progressive muscle relaxation. It is a way to relax one’s body through flexion and relaxation of muslce groups. Science shows it’s quite effective on people with hyperactivity. I can tell from my own experience that this is true. I still “meditate” about once daily. Though, surprisingly, not on weekends. I don’t know why, but for some reason I prefer not to meditate on weekends. I call it meditation, because all the benefits commonly known from “regular” meditation, I get from PMR as well. The quieting of thoughts, the transcendency, the ability to isolate thoughts and feelings, etc.
Since I started my journey into becoming a calmer self, I also learned a lot about spirituality, Buddhism, forgiving, our nervous system, muscles, and many other things going along those lines. My (back then not) ex-girlfriend started a career as yoga teacher. That was one of the things that got me into spirituality in the first place. I’m still very glad I came across Fully Present. This was one of the best reads I ever had on this topic, mainly because it is written from the scientists eye, analyzing the science behind meditation and spiritualism. Recently I met a new friend. We were eating out and she told me she thought that I seemed to radiate a certain kind of calmness. “Calm” wasn’t a term anybody would have used to refer to me some time ago. It shows how long a way I have come. I was always, and luckily still am, a very energetic person. That’s just something you get for free by being hyperactive. You are very upbeat, your mind goes quick, and your body wants to move all the time. I found that balance is absolute key to calmness and being quiet.
It is because I allow my body to perform (sort of) intensive workout, it is because I allow myself to freak out, it is because I allow my heart to beat, it is because I allow myself to have emotions, that I am able to be slow, calm, and relaxed, when I need to. See, I wasn’t like this when I started out, I decided for it. I still need to decide for it, every single day.
What I learned from PMR is relaxing groups of muscles at will. The way PMR is performed: you flex, say, your forearm, you concentrate on that flexion, then you let go, and feel into the relaxation. If you do this a certain time, you suddenly feel where muscles are tight. Again, when some time passes after that, your can turn off tight muscles from your head. When I feel a cramp or something like that now, I go “let go” in my head and the muscle relaxes. It is mere exercise that allows me to do that. There’s no magic formula, just pure doing and doing. When I sit in front of a beautiful woman, I go: “stay calm, relax”, in my head, and my body does what it has been trained to do. It is just execution, execution, execution, but my head needs to set the trigger. I need to be aware of the situation, I need to be there when I want to be that way. The way hyperactivity works is, is it pulls you away, constantly, into the rabbit hole. I need to realize: “Am I still relaxed or is my body starting to go too quick? If yes, what can I do about it right now?” This kind of thinking has helped me in many ways, not just for my own safekeeping. I feel situations that I’m not aware of. I feel where I am distracted and think of other things. The barrier where I am able to make a conscious decision, to be aware, has lowered. The problem is I suddenly also feel all the situations that I am not aware. Things that are automated. Sad sometimes. Think of the last time you said “love you” to your favorite person, and just said it because that’s what you did for the last couple of years. What if that person suddenly dies. Wouldn’t you want that last moment you saw them to be special? That’s what awareness does to you. Cruel, in a way.
What also helped was having strict rules about what can be and what can’t. Planning, planning, planning. I was a planner ever since I got out of uni, almost 8 years ago, but planning has become a tool that I can use to prepare my body for moments where it can do its things, and when I need to have control over it. It also helps me to structure things. I am sometimes worried about the amount of stuff I plan and the rigidity of planning. But it is that rigidity that helps me to go into automation mode. I need to have this structure, it needs to be strict, otherwise I couldn’t perform so well. I don’t do this all the time, because as I wrote earlier, balance is absolute key. Where structure is, there is chaos. I have days that I don’t plan at all and I preasure these days just as much as those that are planned. I set priorities and areas of focus, that’s what gets me started. Planning is key to keep balance. I learned after my break-up how much of our relationship was part of my balance. I needed some time to figure out how to keep balance again on my own.
A word on drugs. I am still against taking drugs. When I met my coach back then, he said: “Take the drugs, that’s the easy way out, but you’d probably have to take the drugs for the rest of your life. The second option would be to work on the root causes. This takes more time and effort, but you wouldn’t have to (buy and) take drugs.” My answer is obvious at this point. What he didn’t say was that I would have to take a different “drug” for the rest of my life, every day (apparently not on weekends though). I prefer to take this drug, because this journey has given me so much. There’s an entirely different way of thinking about things that I haven’t considered before, but are now part of my reality. Spirituality has given me the opportunity to be my own therapist, it has given me the ability to be here when I want to, it allows me to forgive myself, and others. But, again, I also gained the ability to realize all the moments I wasn’t there, I didn’t forgive, I hurt myself. If I’d take the drugs, I wouldn’t have had this journey. I would, possibly, still be angry about myself, how stupid I am to do certain things, probably still be that person I was back then, in a more evolved form. But I didn’t go that way. Luck? Awareness? Stupidity? Who knows. It’s just not part of what I am today.
What I also learned from all of this is why certain things in my life are just the way they are. I always enjoyed fast, mostly aggressive, electronic music. I also enjoyed an unhealthy amount of skate punk in my early 20’s. The bestest band of all time still is Millencolin1. I think my body reacts to this music, and therefore I, in my brain, enjoy this music too. Fast rhythms, that sort of thing turns me on. This also goes in line with the opinion that our nervous system is part of our intelligence. Most humans think of intelligence as something that is in our head2. But we are human. Our body is part of us. Our body is intelligent on its own, we just don’t “think” of things it does actively. There’s an entire “thing” attached to our head that does amazing things, and we don’t think it’s contributing to our whole-self being. Mind and body are the same thing.
I enjoy working fast, too. I couldn’t do it all the time though, if I wouldn’t take regular breaks. I’d burn out too quickly. My body is human after all. Though my body has a special ability to have a higher energy level, that doesn’t mean I can use my body “more”. I’d use up my body, I’d hurt myself.
Sport. I started working out about 10 years ago when I moved out of my parent’s house and into my own room, to study in Munich. First at home, to keep balance from sitting so much. It quickly evolved into riding my bike and going to the gym, where I learned running. When I started, I realized soon that I want this to become part of my life. It felt good. Now 10 years after, it has become part of my life. I read many books and articles on fitness, muscles, the nervous system, etc.. A trainer once told me at a gym I was back in 2006 (already in Stuttgart) that many people who go to the gym, get a certain workout plan, and then just stick with it until they cancel their membership. He said that a new workout plan should be made about every 3 months. So I began working with my various trainers every 3 months to alternate the route I was taking. In my current gym, member since 2011, my trainer and I recently had a discussion where he said: “Why do you even come to me anymore? You know all this stuff pretty darn well. Even if you don’t, then you can just ask any random trainer in this studio. We shouldn’t meet to discuss what exercises you do, maybe, really maybe, the route you take. The rest you can do by yourself.” I thought about it and he was right. I can do this by myself. I got into calisthenics/functional training in 2010, back then it didn’t have a fancy name (or even an entire industry behind it). I remembered that time and thought, let’s cancel my gym membership for a month and see how well I do on my own, with no equipment at all. It was a great month, but I missed going somewhere to do my exercises. I am now back in the gym, mixing calisthenics with weight training. I will continue going by bike or by foot anywhere I can, I will continue running once weekly.
Ten years ago I was a different person. Who would have known I’d become this? I never thought I would, but here I am.
If you have any questions on hyperactivity, exercising, relaxation, meditation, anything mentioned here, feel free to ask in the comments or catch me on Twitter.
“DropboxAppSync is a simple utility that will relocate any Application’s Support folder to your Dropbox account so that it can be shared across multiple Macs.”
DropboxAppSync automates creation of symlinks for Application Support folders. Great idea, give it a whirl if you have a use for it.
Movist is nice. It not only supports everything QuickTime and FFmpeg plays, but also what both support. What I mean by that, if you have a video file open, you can re-open it again with the other decoding engine. Just choose Reopen with … from the File menu.
Version 2.1.1 of Markdown for Keyboard Maestro now available
Version 2.1.1 of Markdown for Keyboard Maestro is now available!
As the version number indicates this is just a minor update. There’s nothing majorly new, just one small bug fix to the Header macro. I had a typo which prevented this macro from working.
OS X Mavericks added some features to “labels”. Previously files and folders were only able to have a color label, now these labels can also have tags. Color labels are now essentially tags with a certain name which also can have a color.
Mavericks also adds the ability to Sort by Tags from every window. This means we can (ab)use this feature to get custom sorting for files.
I have a folder called Watch Later, especially useful when traveling. Let’s be honest, when you go on a travel, you put every single possible movie you may want to watch on your disk so that you can watch everything offline, because when will you have a decent enough connection to watch, right?
The key here is: what priority do you give to watching movies?
Set up some tags 1, 2, and 3, then choose Tags from the Arrange By menu.
Here’s a promising repository for you to watch. A guy by the name of MaddTheSane has been working on Perian. The last commits are only a couple of days old. Maybe we’re going to see an updated version of Perian coming out soon? That would be great!
Lifehacker compares prices of various goods on Amazon and supermarkets. The result is not hugely different from what you might expect. What Lifehacker is totally missing here is valuing time and travel time saved against an item’s actual price. I’m sure that the calculation would be very different then.
A couple of weeks ago a befriended developer sent me a beta app and asked that I take a look at it. The app is called Think About It by Bone Desert Software Limited, a decision assistant, which is now publicly available.
I now have three apps on my device(s) to help me make decisions. Sometimes I’m torn between two options for something easy like “do I go to the gym today or tomorrow?” These kind of decisions have no effect on my life, because it doesn’t matter if I go today or tomorrow, all it matters is that I go. Decide Now! helps in this instance.
I also have Decision App, which is handy for more elaborate decisions. The app has some of the most useful decision matrices included. The only downside here is that the app doesn’t really improve the decision making process.
This is where Think About It comes in. TAI allows you to create a Decision and add Criteria that must be met to determine the most suitable solution. Rating these Criteria allows the app to calculate a result automatically. Criteria can be something measurable, like the price of an app, or something less defined like personal preference or a feeling.
Once multiple Criteria have been created, a new option shows up: “How important is this?” Here a user can rate the importance between Criteria. For instance, in the example of a decision whether to buy an app or a competing one, price may be more important than UI design. Think About It reports any inconsistent rating. These inconsistencies have to be resolved before Think About It is able to make a choice. The app also assists in the process of highlighting where the inconsistency is likely to be.
When all Criteria have been added, it is time to add Choices. Choices are basically the alternative outcomes you are considering. In the above example, the iPhone apps themselves. The last step is to measure how well a choice performs against the other choices for each Criteria. When everything is entered, the app will present a calculated, unemotional, winning result based on true facts.
Now obviously using the term.ly bookmarklet would be way to easy, plus we would lose the benefit of using a highly sophisticated iOS app that supports a great URL scheme.
You need to create an app on Pushover for this. Don’t forget to assign user and API key in the Shell script action, then you’re good to go.
I left the other URL parameters in the script so that you can see what other options you have on Pushover.
Obviously there had to be a better way, right? Right? Oh was I wrong. Read the comments (from 2006!) and have a good laugh. I don’t know about you, but when I name my files I just don’t give a fuck.
The general rule is simple: as long as the system supports certain characters, I see no reason to avoid certain characters.
I spend quite some time working with editors and designers. I giggle the first time I see design_1.psd popping up in Growl. I set some time aside for these folks and explain the advantages, but also the disadvantages of such file naming conventions. I explain that they can use whatever they feel like, because the computers we use have Unicode. As long as it’s useful there’s no reason to castrate file names in an unreadable manner.
Heck, I even use Emoji’s for filenames sometimes, just because I feel like it and I know that I can. And so should you.