Jump to content

Workflow to set TextExpander text


Recommended Posts

Posted
I am writing a paper with a fairly substantial lit review.  I manage my citations in <a href="http://www.thirdstreetsoftware.com/site/SenteForMac.html>Sente</a>.  Sente assigns a citation key to each reference in its database (usually the lead author's first name and the publication year).  When writing, I can point to various references in the manuscript by embedding the citation key in curly brackets {Colyer 2013}.  On compile, the software handles all the tedium of converting the reference to the proper citation format (APA, Chicago, MLA, etc) and generates a Bibliography page).  There are various switches in the cite key that modify how Sente renders the citation in text.  For instance {Colyer 2013@12} will be converted to a page number reference (Colyer 2013, pg 12); {%Colyer 2013} strips the author (2013), etc and so forth.

 


">TextExpander</a> to insert these cite key permutations with a minimum of friction.  [Yes, I know that Alfred2 has text expansion capabilities and I may be open to using them as a solution to my problem.  But TextExpander's ability to embed a snippet in other snippets is fundamental to my workflow.  TextExpander allows me to set one snippet containing the author & year and then embed that snippet in other snippets that generate standard citations, page number citations, and author omitted citations.  In my current writing workflow, I manually modify the author year in the base snippet and it works great.

 

It occurred to me that Alfred2 should be able to let me modify the Author Year Snippet through a keyword trigger further reducing my writing friction.  I started teaching myself AppleScript and with the help of Smile's excellent tech-support, I now can populate the text of my root Cite Key through AppleScript.

 

I tried to create a keyword workflow in Alfred2: ck foo 2012 which should pass the string foo 2012 to a variable _citekey which TextExpander will set to the plain text expansion of my root cite key.  My workflow does not work.  When I trigger the workflow the plain text expansion of the target snippet does not change.

 

Can someone help me figure out what I've done wrong?


on alfred_script(q)
-- This script sets the cite key to a variable _cite key
-- Next we want to try and populate the _citekey variable by Alfred.

set _citekey to q

on snippet_by_abbreviation(abrvStr) -- written by Smile Tech Support on 2013-05-09
set theSnippet to null
tell application "TextExpander"
repeat with theGroup in every group
set theSnippets to (snippets of theGroup whose abbreviation is abrvStr)
if (length of theSnippets > 0) then
set theSnippet to item 1 of theSnippets
exit repeat
end if
end repeat
end tell
return theSnippet
end snippet_by_abbreviation

set mySnip to my snippet_by_abbreviation("!CK!")
if (mySnip ≠ null) then
tell application "TextExpander"
set (plain text expansion of mySnip) to _citekey
end tell
end if
end alfred_script
Posted (edited)

Carlos.  Thank you!  This is exactly what I wanted it to do. 

 

Comparing your code to mine, I now understand that if I wish to pass a string from Alfred to Applescript, I must:

 

a. include "{query}" in the set command, and

 

b.  declare the variable as text.

 

and

 

c. Your code hooks into /usr/bin/osascript which is different from the Run NSAppleScript action baked into the Workflow Action list.

 

I really appreciate your help.

Edited by cjcolyer
Posted

Carlos.  Thank you!  This is exactly what I wanted it to do. 

 

Comparing your code to mine, I now understand that if I wish to pass a string from Alfred to Applescript, I must:

 

a. include "{query}" in the set command, and

 

b.  declare the variable as text.

 

I really appreciate your help.

 

Great. Note that we are also working only with AppleScripts language.

  • 5 months later...
Posted

@Carlos, 

 

As an avid TextExpander user I wanted to try your workflow.

But I have to admit while I red cjcolyer post + understand how cool this is

I can't make it work... 

 

Could you describe more precisely how I can use it ?

 

Thank you.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...