Hi. The following script adds an appointment to iCal (to the “Home” calendar). The appointment should have the item link in the URL field of the new appointment (allowing access to the relevant DT entry from the new appointment).
This script usually runs fine. For instance, if the DT entry is a text file, I get a new appointment with the same title as the text file and the item link in the url field of the appointment. Clicking on the item link brings up the text file in DT.
However, this script does not work if the DT item is an email which has been added to DT from the Mail application. Note that the URL prints fine in the dialog box which I have added to the code to check its integrity. But the item link isn’t added to the calendar entry’s url field. I think this might be a bug.
Thanks for any help.
Tom S.
(*
Create an appointment from the currently selected item.
Bug (?) when a mail item is selected.
*)
try
-- Get the selection
tell application id "com.devon-technologies.thinkpro2" to set thisSelection to the selection
-- Error handling
if thisSelection is {} then error localized string "Please select a document or group, the try again."
if (length of thisSelection) > 1 then error localized string "Please select only one document or group, then try again."
-- Get and format the data we need
tell application id "com.devon-technologies.thinkpro2"
set thisItem to first item of thisSelection
set theSummary to (name of thisItem) as string
set thisGroup to current group
set theName to name of thisItem
set theUUID to uuid of thisItem
set theURL to "x-devonthink-item://" & (uuid of thisItem as string)
-- Note well that this string displays fine in this dialog box
display dialog theURL buttons {"Cancel", "OK"} default button 2
end tell
-- Let the user choose when to receive the reminder
-- Convert array into localized arrays
-- Set date
set theStartDateString to (date string of (current date)) as string
set theStartDate to (date theStartDateString)
set theEndDate to theStartDate
set theChosenCalendarName to "Home"
-- Add new to do to iCal
tell application id "com.apple.iCal"
tell calendar theChosenCalendarName
-- Create new to do
-- Note that theURL which displayed fine earlier is not assigned to caledar appointment
set theEvent to make event at the end of events with properties {summary:theSummary, start date:theStartDate, end date:theEndDate, url:theURL, allday event:true}
tell theEvent
set theAlarm to make display alarm at the end of display alarms with properties {trigger date:theStartDate, trigger interval:-15}
end tell
-- Show new to do item in iCal so that the user can edit it right away
view calendar theChosenCalendarName at theStartDate
show theEvent
activate
end tell
end tell
on error errMsg
display alert (localized string "Error when adding item to iCal") message errMsg
end try