display group selector question

Hi,

I’m trying to create a script that will allow me to copy an email from mail.app into devonthink. I’ve copied the existing script but I am trying to modify it to do two things:

  1. Ask me to apply a label
  2. Ask me which group to put the message in.

I can get a group dialogue box to open using “display group selector,” but the messages never save in the folder I specify. Any thoughts on how I might pull this off?

Thanks for any help anyone can offer with this.

Just post the code of your script, that will simplify the debugging.

-- Import selected Mail messages to DEVONthink Pro.
-- Created by Christian Grunenberg on Mon Apr 19 2004.
-- Copyright (c) 2004-2009. All rights reserved.

-- this string is used when the message subject is empty
property pNoSubjectString : "(no subject)"

tell application "Mail"
	try
		tell application id "com.devon-technologies.thinkpro2"
			if not (exists current database) then error "No database is in use."
		end tell
		set theSelection to the selection
		if the length of theSelection is less than 1 then error "One or more messages must be selected."
		repeat with theMessage in theSelection
			my importMessage(theMessage)
		end repeat
	on error error_message number error_number
		if error_number is not -128 then display alert "Mail" message error_message as warning
	end try
end tell

tell application id "com.devon-technologies.thinkpro2"
	set theLocation to display group selector "Destination" buttons {"Cancel", "OK"}
end tell

on importMessage(theMessage)
	tell application "Mail"
		try
			set theDateReceived to the date received of theMessage
			set theDateSent to the date sent of theMessage
			set theSender to the sender of theMessage
			set theSubject to subject of theMessage
			if theSubject is equal to "" then set theSubject to pNoSubjectString
			set theSource to the source of theMessage
			set theReadFlag to the read status of theMessage
			tell application id "com.devon-technologies.thinkpro2"
				set theRecord to create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string)} in incoming group
				set unread of theRecord to (not theReadFlag)
				set label of theRecord to 1
			end tell
		on error error_message number error_number
			if error_number is not -128 then display alert "Mail" message error_message as warning
		end try
	end tell
end importMessage

So, this is just a modification of the script that comes with devonthink… (almost) no original work here.

I have managed to get devonthink to bring up a group selector using:

tell application id "com.devon-technologies.thinkpro2"
	set theLocation to display group selector "Destination" buttons {"Cancel", "OK"}
end tell

But I cannot get the messages to go into the selected folder.

Also, I was able to hard-code in the label:


				set label of theRecord to 1

This is fine, I can make 7 different scripts to access my 7 labels however it would be nicer if I could select the label on demand.

Any thoughts?

jeff

The script displays the group selector, sets the variable “theLocation” but you don’t use it afterwards. E.g. replace “in incoming group” with theLocation after adding this parameter to importMessage.

Hi Christian,

Thanks for pointing that out. I’m still just learning applescript and missed that little detail. Script works like a charm. Now, is there a way to bring up a selector for the label or do I need a separate script for each label?

j.

You could use the standard “choose from list” command to select a label.