TextExpander would remove the snippet, and try to expand with what was on the clipboard.I would type the variable text followed by the snippet.After literally hours of banging my head against this did I happen to notice the following behavior, and only after adding various delays. I thought that maybe some combination of JavaScript for Automation and TextExpander wasn’t handling the asynchronous System Events. This led me down a path of assuming the issue was timing. Other times it would seemingly respond with the copied text as expected while even other times it would return the copied text in some garbled state. Instead the snippet would only fail sometimes. This is because my original attempt to select and copy text didn’t simply fail. Learning this behavior was harder than finding the workaround. Perhaps the biggest hurdle was learning that TextExpander interrupts keyboard input while expanding. Challenge 1 - TextExpander Keyboard Interruption This seemed like a fairly straight forward plan, but executing it presented surprising challenges. Create a JavaScript snippet that uses System Events to select and copy that text, then read it back from the clipboard into a JavaScript variable.Precede my snippet with some extra text to represent my variable.The Proof of Conceptīecause TextExpander supports AppleScript and its younger sibling, JavaScript for Automation, I knew it’d have access to System Events so my idea was simple. For those not interested in the history of this project, you can bail now and view the source here. Having not found a solution on the web, I decided to try to figure out my own workaround. In theory I could have brute forced this and have some number of different hardcoded snippets, but that would be inelegant and cumbersome to maintain 1. What I have long wanted to do is simply tell TextExpander to get me the URL of the next, previous, or any other tab. The site in question may be just one tab over, but I am stuck taking my attention away to manually copy its URL. What if the url I need is on another tab? The best example of this is when the application I am using happens to be web-based, like Google Docs, then that web application will always be the current tab. Pretty handy, right? But there’s a problem. So now I can easily grab the URL in Safari whenever typing “ aUrl”. Nothing illustrates this better than the snippet I use for getting the url of the current tab from Safari: var safari = Application("Safari Technology Preview") As someone who heavily uses TextExpander’s Script Snippets feature, the benefit of being able to pass a variable to a snippet has long seemed obvious. Assign a Keyboard Shortcut to Move Messages to a Folder in Apple Mailġ0.Just over two years after my snippet renaissance, I’ve finally put some time into working together a hack to address one of my biggest wants - snippet variables.Yearly Recaps: A Monthly, Contextual, Plain-Text Journaling System.How to Select the "OK" Button via Keyboard for Text Dialog Boxes (macOS).Spreadsheet tip: "is not" or "is not equal to".The One-Line-Per-Day, One-Page Plain Text Daily Journal.Meditation Analogy: The River Of Thoughts.Meditation Is Like That Feeling You Get When Traveling Solo, All The Time.I set up Drang’s snippet as a companion, for those intermittent times when I want to modify the text prior to insertion.īeen wanting to add this to my setup for some time. Drang’s Markdown & TextExpander post which helped me formulate this snippet. If you’d like to have some control over the link text before the Markdown link is inserted, head over to Dr. My old method was to use a Safari bookmarklet, which I had to click, then Copy, Esc the dialog, switch to t nvALT, Paste. Now, when I find a link I want to save, I just switch over to nvALT as per usual, get the cursor where I want it, and invoke the snippet. Be sure to set the snippet as an AppleScript snippet for this to work properly. I set up the TextExpander shortcut mdL for this. tell application "Safari" set theURL to URL of front document set theName to name of front document end tell get "(" & theURL & ")" Here’s a simple AppleScript which can be used with a TextExpander snippet, or as a Service via the macOS Automator app, that when invoked will insert the title and URL of the frontmost Safari tab, formatted as a Markdown link.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |