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:
The question I have is how I get the response to appear when I execute the TextExpander snippet.
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.
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:
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.
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:
(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.
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?