Problems writing an AppleScript record to reference a partic

I have modified one of the scripts provided with DEVONThink Pro to copy email into a database. Thus far, the syntax for writing an AppleScript record to reference a particular group is escaping me.

I’ve learned from the forums and looking at your examples that when a group is created with AppleScript, a record is returned to the script allowing one to reference a particular group (if the record is captured in a variable) like so:

tell application id “DNtp”
set destinationGroup to create location “/ForumMail”
class of destinationGroup – just to make sure it’s an AppleScript record
end tell

–>parent id 47243 of database id 2 of application “DEVONthink Pro”
–> record

The name of an existing group can also be used to generate a group reference record:

tell application id “DNtp”
set theGroup to get record at “/ForumMail”
end tell

–>parent id 47243 of database id 2 of application “DEVONthink Pro”

But, I can’t seem to form an AppleScript record directly in the script that works as a reference to a particular group

I tried:

set theGroup to {parent:id & 47243, database:id & 2} but that returns nonsense

also:

{id: 47243} ignored. Goes to inbox - Same as no reference being provided.

Obviously, I don’t use the record class much when I script and I’m not very good at writing them.

So, how do you write “parent id 47243 of database id 2 of application “DEVONthink Pro”” as an AppleScript Record?

Or, do you always have to capture it from the application into a variable?

D-;

E.g. like…


set theDatabase to get database with id 2
set theGroup to get record with id 42243 in database theDatabase

You wrote:
set theDatabase to get database with id 2
set theGroup to get record with id 42243 in database theDatabase

Perfect! Thank You

I really need to spend some time with the application’s dictionary. I sometimes wish dictionaries were a bit more like man pages and included some examples of the syntax.

D-;

I replied before I tried your solution, Unfortunately it doesn’t work.

tell application “DEVONthink Pro”
get database with id 2
–> database id 2
get record with id 47480 in database (database id 2)
–> error number -1700 from database id 2 to integer

I guess I’ll stick with grabbing the AS record using the group name,
(set theGroup to get record at “/AppleScriptLists”)
but I can’t get that to work if the group is a subgroup of another group.

Thanks for your help.

D-;

It’s working fine over here, which version of DEVONthink Pro are you using? In addition, IDs are recommended only for temporary usage as they’re not persistent. Usage of UUIDs is recommended instead.

I’m on version 2.3.2 running OS X 10.7.3.

This is my complete script, that fails. Note, I used “current group” just prior to running this script to verify group id is correct.

– Created by Christian Grunenberg on Mon Apr 19 2004. Mod by ME.
– Copyright © 2004-2009. All rights reserved.

– this string is used when the message subject is empty
property pNoSubjectString : “(no subject)”

tell application “Mail”
set theMessages to every message of mailbox “AS-Users”
repeat with theMessage in theMessages
my importMessage(theMessage)
end repeat
end tell

on importMessage(theMessage)
tell application “Mail”
try
tell theMessage
set {theDateReceived, theDateSent, theSender, theSubject, theSource, theReadFlag} to {the date received, the date sent, the sender, subject, the source, the read status}
end tell
if theSubject is equal to “” then set theSubject to pNoSubjectString
tell application id “com.devon-technologies.thinkpro2”
–set theGroup to get record at “/AppleScriptLists” --get an AppleScript record referencing a group using the group’s name
set theDatabase to get database with id 2
set theGroup to get record with id 47480 in database theDatabase
set theRecord to create record with {name:theSubject & “.eml”, type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string)} in theGroup --pass record theGroup
set unread of theRecord to (not theReadFlag)
end tell
end try
end tell
end importMessage

This is the AS reply:
tell application “DEVONthink Pro”
get database with id 2
–> database id 2
get record with id 47480 in database (database id 2)
–> error number -1700 from database id 2 to integer
end tell

I would like to try using UUID. How do you get the UUID and how do use it in your script?

Thanks
This doesn’t seem to be going well for me.
Too many hours pouring over the dictionary and only seconds of getting anywhere.
–Not critical, just getting frustrated because I usually can figure obscure AS incantations out. At this point I have no idea why your code doesn’t work(?)

D-;

Neither the database ID nor the record ID are persistent and might be different after restarting or optimizing/closing/opening databases.

The easiest & most readable solution is probably something like…


tell application "DEVONthink Pro"
	get record at "/MyGroup" in (database named "MyDatabase")
end tell