# TextExpander Applescript to Retrieve DT3 Data

**URL:** <https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993>\
**Category:** Automation\
**Created:** [June 8, 2021, 1:45am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993 "2021-06-08T01:45:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkaplan](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/r/a3d4f5/32.png) [@rkaplan](https://discourse.devontechnologies.com/u/rkaplan)\
**Post date:** [June 8, 2021, 1:45am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/1 "2021-06-08T01:45:48Z")

</div>

I am trying to experiment with TextExpander to retrieve data from Devonthink using Applescript - this was inspired by a recent Forum discussion on MPU with @korm on a related question with Javascript

This script within TextExpander works correctly in its viewing/test mode:

![image](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/8/1/816a81b1e5496576ec4b4304b8e1cc21b7c7f514.png)

The question I have is how I get the response to appear when I execute the TextExpander snippet.

I read the TextExpander documentation at [TextExpander Help: AppleScripting TextExpander](https://textexpander.com/help/desktop/scriptingte.html) and tried this:

 ![image](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/5/8/58c5c4fa5d6760c2df956e9cfe44da7bfe772b82.png)

I get this error:

![image](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/d/1/d1792e151ce31bb4bbbce2a7b41c681e33a64dba.png)

I know I am close - what am I missing so I can return the Applescript response as the output of the snippet?

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [June 8, 2021, 2:29am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/2 "2021-06-08T02:29:39Z")

</div>

I don’t use TextExpander but doesn’t it highlight the line it’s erroring on?

---

<div class="post-metadata">

**Author:** ![rkaplan](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/r/a3d4f5/32.png) [@rkaplan](https://discourse.devontechnologies.com/u/rkaplan)\
**Post date:** [June 8, 2021, 2:34am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/3 "2021-06-08T02:34:46Z")

</div>

It does not highlight it, but by trial and error I know the problem is this line:

`Expand abbreviation "jsdt3"`

That line seems necessary based on the documentation. But interestingly I cannot find either “Expand” or “abbreviation” in the current Applescript dictionary for TextExpander.

So I expect there may be some newer or alternate way to specify what text should actually be inserted as the Macro response.

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [June 8, 2021, 2:36am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/4 "2021-06-08T02:36:21Z")

</div>

> I cannot find either “Expand” or “abbreviation” in the current Applescript dictionary for TextExpander.

Why did you use those commands then? 🤔

---

<div class="post-metadata">

**Author:** ![rkaplan](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/r/a3d4f5/32.png) [@rkaplan](https://discourse.devontechnologies.com/u/rkaplan)\
**Post date:** [June 8, 2021, 2:38am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/5 "2021-06-08T02:38:31Z")

</div>

> [@BLUEFROG](#):
>
> Why did you use those commands then?

Because that is my interpretation of the documentation here [Scripting TextExpander](https://textexpander.com/help/desktop/scriptingte.html) - but I am certainly open to other ideas

![image](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/8/a/8ad56fa3cda8bddc8cce4e1dbd2cd9bc433f0112.png)

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [June 8, 2021, 2:41am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/6 "2021-06-08T02:41:32Z")

</div>

Move the TextExpander `tell` block out of the DEVONthink one. The editor is definitely showing weird formatting in your screen captures.

---

<div class="post-metadata">

**Author:** ![rkaplan](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/r/a3d4f5/32.png) [@rkaplan](https://discourse.devontechnologies.com/u/rkaplan)\
**Post date:** [June 8, 2021, 2:47am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/7 "2021-06-08T02:47:09Z")

</div>

Same error

(And though the formatting looks weird - it works fine in the TextExpander preview if I do not using the expand instruction.)

 ![image](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/0/0/004b0763754dff212ac90902e878fca33cb18a6b.png)

![image](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/b/a/ba0f0c39b4cb8e31156bd69052e01713ddfffad2.png)

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [June 8, 2021, 2:48am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/8 "2021-06-08T02:48:54Z")

</div>

Try writing the script in Script Editor instead.  
Like I said, I don’t use TextExpander.

---

<div class="post-metadata">

**Author:** ![rkaplan](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/r/a3d4f5/32.png) [@rkaplan](https://discourse.devontechnologies.com/u/rkaplan)\
**Post date:** [June 8, 2021, 2:52am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/9 "2021-06-08T02:52:26Z")

</div>

Interesting - that gives us another clue

So the documentation is wrong?? Or something changed?

 ![image](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/3/d/3dbd2742de4dc814c1bb6208500326df1efe4c21.png)

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [June 8, 2021, 2:54am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/10 "2021-06-08T02:54:41Z")

</div>

> So the documentation is wrong??

It’s certainly possible. The scripting dictionary is manually created.

> Or something changed?

No idea. Again… I don’t use the app. 🙂

---

<div class="post-metadata">

**Author:** ![rkaplan](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/r/a3d4f5/32.png) [@rkaplan](https://discourse.devontechnologies.com/u/rkaplan)\
**Post date:** [June 8, 2021, 2:55am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/11 "2021-06-08T02:55:22Z")

</div>

OK I will ask TextExpander support - thank you

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [June 8, 2021, 2:57am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/12 "2021-06-08T02:57:12Z")

</div>

Open a new script in Script Editor and paste this…

```auto
tell application "TextExpander"
expand abbreviation ";fbreply"
end tell

```

According to the info you posted above, this would appear to function. Does it compile correctly?

---

<div class="post-metadata">

**Author:** ![rkaplan](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/r/a3d4f5/32.png) [@rkaplan](https://discourse.devontechnologies.com/u/rkaplan)\
**Post date:** [June 8, 2021, 3:00am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/13 "2021-06-08T03:00:51Z")

</div>

Same error

 ![image](https://devontech-discourse.s3.dualstack.us-east-1.amazonaws.com/uploads/original/3X/0/4/0446b69f3f2da0f19930bb7b87c59daf737305ed.png)

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [June 8, 2021, 3:05am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/14 "2021-06-08T03:05:44Z")

</div>

Yeah, I’d ask the TextExpander folks on this one.

---

<div class="post-metadata">

**Author:** ![rkaplan](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/r/a3d4f5/32.png) [@rkaplan](https://discourse.devontechnologies.com/u/rkaplan)\
**Post date:** [June 8, 2021, 3:12am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/15 "2021-06-08T03:12:56Z")

</div>

Will do - thanks for the effort trying

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [June 8, 2021, 3:13am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/16 "2021-06-08T03:13:27Z")

</div>

You’re welcome.

---

<div class="post-metadata">

**Author:** ![pete31](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/p/d26b3c/32.png) [@pete31](https://discourse.devontechnologies.com/u/pete31)\
**Post date:** [June 8, 2021, 4:14am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/17 "2021-06-08T04:14:15Z")

</div>

> [@rkaplan](#):
>
> I am trying to experiment with TextExpander to retrieve data from Devonthink using Applescript

As Bluefrog mentioned it’s always a good idea to write scripts in a dedicated script editor app and to paste the working code into other apps. Doing so immediately showed that `abbreviation` isn’t part of the current TextExpander version and that the linked documentation is not for the current version (as you meanwhile know).

You don’t need to expand the abbreviation inside itself via AppleScript - in fact I doubt that it’s possible at all to let an expansion trigger itself via AppleScript as it would probably endlessly trigger itself.

And you don’t need to `activate` DEVONthink to get its selection.

This works over here:

```auto
tell application id "DNtp"
	try
		set theRecords to selected records
		if theRecords = {} then error "Nothing selected."
		set Bigname to ""
		
		repeat with theRecord in theRecords
			set theName to name of theRecord
			set Bigname to Bigname & theName & linefeed
		end repeat
		
		return Bigname
		
	on error error_message number error_number
		if the error_number is not -128 then
			activate -- make sure to add an "activate" if you want to show dialogs
			display alert "DEVONthink" message error_message as warning
		end if
		return
	end try
end tell

```

  

If you want to know why an expansion that uses AppleScript doesn’t yield the desired result include an error Handler (as I did above) that uses `activate` to bring the app in question to the front. Without the `activate` the dialog would be shown anyway but chances are you won’t see it until you activate the app again.

Adding something that tells you that an error occurred is a good idea as without it it’s probably getting quite confusing: You’ll hear TextExpander’s sound but there’s nothing inserted.

---

<div class="post-metadata">

**Author:** ![rkaplan](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/r/a3d4f5/32.png) [@rkaplan](https://discourse.devontechnologies.com/u/rkaplan)\
**Post date:** [June 8, 2021, 4:30am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/18 "2021-06-08T04:30:01Z")

</div>

@pete31

You are indeed a scripting genius

Works perfectly

Many many thanks

---

<div class="post-metadata">

**Author:** ![rkaplan](https://discourse.devontechnologies.com/letter_avatar_proxy/v4/letter/r/a3d4f5/32.png) [@rkaplan](https://discourse.devontechnologies.com/u/rkaplan)\
**Post date:** [June 8, 2021, 11:57am UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/19 "2021-06-08T11:57:16Z")

</div>

@pete31

Looks like you solved something which TextExpander says is unsolvable at the moment - Congrats

> Thank you for contacting Smile Support. I’m sorry to hear that you’re having trouble with your snippet but those AppleScript commands did not make it into the most recent version and there is not currently an alternative. I’ve relayed your request to put this functionality back into TextExpander to our engineers and they will investigate doing that for a future update. If you’d like, you can move back to the last version where these AppleScript commands were available:
> 
> [https://cdn.textexpander.com/mac/TextExpander\_6.5.6.zip](https://cdn.textexpander.com/mac/TextExpander_6.5.6.zip)
> 
> (Note: You can drag this version into your Applications folder which will overwrite the existing application. You can also rename it before dragging to have both versions on your computer. However, only one version can run at a time. Your snippets are safe in a different location and on the TextExpander server.)
> 
> Also, your case is now linked to the open request so we will reach out when the issue is resolved. Let me know if you have any other questions, comments or concerns.
> 
> Thanks for using TextExpander from Smile!

---

<div class="post-metadata">

**Author:** ![Cassady](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/cassady/32/8320_2.png) [@Cassady](https://discourse.devontechnologies.com/u/Cassady)\
**Post date:** [June 8, 2021, 7:39pm UTC](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993/20 "2021-06-08T19:39:14Z")

</div>

This looks very interesting, and fantastic that the DT users are so willing and able to help!

But, if you don’t mind the question — could you maybe explain what you are actually aiming to do with the above? I’m sincerely curious, btw! I’m a heavy TE user as well, but would never have thought of inserting data from DT into a TE snippet — assuming that’s what’s being tried here?

[Next page](https://discourse.devontechnologies.com/t/textexpander-applescript-to-retrieve-dt3-data/64993.md?page=2)
