TexasT's (texasts) wrote,
TexasT's
texasts

  • Mood:

AppleScript and TextExpander 5 and MacJournal

I’m a bit warped sometimes. Case in point…

I was trying to automate some entries in MacJournal using TextExpander 5. Specifically I was trying to automate entry of a certain set of tags for specific topics of entries. Could NOT make this work. I finally got perturbed enough to send off a note to Smile Support (Smile is the developer of TextExpander). (Shameless plug, Smile Software has a couple of great utility type products for Macs, TextExpander and PDFPen. You should totally check them out) Within a day or so they got back to me with a solution to use applescript to automate the [Tag] entries. Heh and it works too, IF you put the cursor in the right field to start with. *laughs*. This was their proposed script:

----
set theText to "42, what_is_the_rule_of_steel, stuff_i_like, thoughts,"

delay 0.15
tell application "System Events"
repeat with i from 1 to count characters of theText
keystroke (character i of theText)
end repeat
end tell
-----

This script basically puts the tags in character by character with a delay of .15 seconds (I think) and positions the cursor at the end of the last tag [thoughts]. What they didn’t tell me was how to put it in the snippet. So that took a bit more research. Not hard, just not documented well. Then today I got the idea to add 4 [Tab]s. This would position the cursor in the entry area of the window. So I wrote a snippet for that:

----
%key:tab% %key:tab% %key:tab% %key:tab%
----

This is not applescript but merely a snippet that says press the [Tab] 4 times. Worked fine, except it put in a [Space] at the end. The next iteration fixed that. Put simply, I merely removed the spaces between the pieces of text:

----
%key:tab%%key:tab%%key:tab%%key:tab%
----

Perfect. Except now I had to run two snippets. I had read you could nest (or embed) snippets within snippets. I know! Deep, right? Well, except I couldn’t make it work. Might have been the way I put it together. I don’t know, but I abandoned that idea fairly quickly.

Then I got the idea to create another applescript just for the 4 [Tab]s:

----
tell application "System Events"
repeat 4 times
keystroke tab
end repeat
end tell
----

Took a bit of research, but I did get that one right. So I created a snippet for that. Again, perfecto.

But I still had to make another snippet to run these 2 pieces of code. Not very efficient. Took some more research and some trial and error (heh - redundant). The end product works like a charm:

----
set theText to "42, what_is_the_rule_of_steel, stuff_i_like, thoughts,"

delay 0.15
tell application "System Events"
repeat with i from 1 to count characters of theText
keystroke (character i of theText)
end repeat
repeat 4 times
keystroke tab
end repeat
end tell
----

Hah! Simple! Sometimes it takes me a while, but I get there in the end…

There might be something to this [AppleScript thing]… Hmmmmm. More time needs to be devoted to this. I’ve already got a book or two on it and {Automator]. Almost makes me want to revive one of my old blogs “There and Mac Again”. Started in 2007, right after I got my MacBookPro, haven't made an entry there since 2009… Time flies and all that.

But I don’t really have time to generate content for it, so right now? Probably will not be happening. And I’d need to figure out some way to monetize it…
Tags: 42, tech_support
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 2 comments