Large Conference Management A DT3 User Case Study

Maybe this script is useful. It’s a variation of Script: Create custom date register.

It creates a group structure depending on property theDateFormat and property theMinutesToAdd.

Example output with theMinutesToAdd set to 60 :

Note: In the second dialog you’ll have to set the end date to your desired end date plus one day.

-- Create custom date register (with time)

-- Date Format Patterns:		https://unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns

-- Examples:
-- "yyyy/yyyy-MM/yyyy-MM-dd" --> 2021/2021-03/2021-03-01
-- "'Random string' yyyy/'Test' yyyy-MM/yyyy-MM-dd" --> Random string 2021/Test 2021-03/2021-03-01
-- "yyyy/yyyy-MM/dd. MMMM yyyy" --> 2021/2021-03/01. März 2021
-- "yyyy/QQQ yyyy/yyyy-MM/yyyy-MM-dd" --> 2021/Q1 2021/2021-03/2021-03-01
-- "YYYY/'KW' ww YYYY/YYYY-MM-dd, E" --> 2021/KW 09 2021/2021-03-01, Mo.
-- "e EEEE/yyyy-MM/yyyy-MM-dd" --> 1 Montag/2021-03/2021-03-01

-- Note: If you use a slash "/" make sure to escape it "\\/"

use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

property createGroups : true -- set to false while testing 
property theDateFormat : "LLL d/LLL d - HH':'mm" --> Dez 5/Dez 5 - 01:00
property theMinutesToAdd : 60 -- 1 hour

set theCalendar to current application's NSCalendar's currentCalendar()
set theCalendarOptions to current application's NSCalendarMatchNextTime
set theDefaultStartDate to current application's NSDate's |date|()
set theDateComponents to current application's NSDateComponents's alloc()'s init()
set theDateComponents's |day| to 1
set theDateComponents's |month| to 1
set theDefaultEndDate to theCalendar's nextDateAfterDate:theDefaultStartDate matchingComponents:theDateComponents options:theCalendarOptions
set theDateFormatter to current application's NSDateFormatter's alloc()'s init()
set theDateFormatter's timeZone to (current application's NSTimeZone's timeZoneWithName:"GMT")
set theDateFormatter's dateFormat to "yyyy-MM-dd"

tell application id "DNtp"
	try
		if not (exists viewer window 1) then error "Please open a window"
		
		activate
		
		set theStartDate to missing value
		repeat while theStartDate = missing value
			set theStartDate to theDateFormatter's dateFromString:(display name editor "Create Register" info "Start Date:" default answer ¬
				(theDateFormatter's stringFromDate:theDefaultStartDate) as string)
		end repeat
		
		set theEndDate to missing value
		repeat while theEndDate = missing value
			set theEndDate to theDateFormatter's dateFromString:(display name editor "Create Register" info "End Date:" default answer ¬
				(theDateFormatter's stringFromDate:theDefaultEndDate) as string)
		end repeat
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

set theNSOrderedAscending to current application's NSOrderedAscending
if (theStartDate's compare:theEndDate) ≠ theNSOrderedAscending then set {theStartDate, theEndDate} to {theEndDate, theStartDate}

set theDateComponents's |month| to 0
set theDateFormatter's dateFormat to theDateFormat
set thisDate to theStartDate
set theDateStringArray to current application's NSMutableArray's arrayWithArray:{theDateFormatter's stringFromDate:theStartDate}

repeat
	if theMinutesToAdd > 0 then
		repeat
			set theDateComponents's |day| to 0
			set theDateComponents's minute to theMinutesToAdd
			set thisDate to (theCalendar's dateByAddingComponents:theDateComponents toDate:thisDate options:theCalendarOptions)
			
			if (theEndDate's compare:thisDate) ≠ theNSOrderedAscending then
				(theDateStringArray's addObject:(theDateFormatter's stringFromDate:thisDate))
			else
				exit repeat
			end if
		end repeat
	end if
	
	set theDateComponents's |day| to 1
	set theDateComponents's minute to 0
	set thisDate to (theCalendar's dateByAddingComponents:theDateComponents toDate:thisDate options:theCalendarOptions)
	
	if (theEndDate's compare:thisDate) ≠ theNSOrderedAscending then
		(theDateStringArray's addObject:(theDateFormatter's stringFromDate:thisDate))
	else
		exit repeat
	end if
end repeat

if createGroups = true then
	
	script s
		property theLocations : missing value
	end script
	
	set s's theLocations to theDateStringArray as list
	
	tell application id "DNtp"
		try
			set theDatabase to current database
			set theGroup to current group
			if theGroup ≠ root of theDatabase then
				set theGroupName to name of theGroup
				if theGroupName contains "/" then set theGroupName to my escapeSlash(theGroupName)
				set theGroupLocation to location of theGroup & theGroupName & "/"
			else
				set theGroupLocation to "/"
			end if
			set theContainerName to "Register"
			
			if exists record at theGroupLocation & theContainerName in theDatabase then
				set theDateFormatter's timeZone to current application's NSTimeZone's localTimeZone()
				set theDateFormatter's dateFormat to "yyyy-MM-dd HH.mm.ss"
				set theContainerName to theContainerName & space & ((theDateFormatter's stringFromDate:(current application's NSDate's |date|())) as string)
			end if
			
			show progress indicator "Creating Register... " steps (count (s's theLocations)) as string with cancel button
			
			repeat with thisLocation in s's theLocations
				step progress indicator thisLocation as string
				create location theGroupLocation & theContainerName & "/" & thisLocation as string in theDatabase
			end repeat
			
			hide progress indicator
		on error error_message number error_number
			hide progress indicator
			if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
			return
		end try
	end tell
	
else
	set theDateStringList to theDateStringArray as list
	return item 1 of theDateStringList
end if

on escapeSlash(theText)
	set d to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "/"
	set theTextItems to every text item of theText
	set AppleScript's text item delimiters to "\\/"
	set theText_escaped to theTextItems as string
	set AppleScript's text item delimiters to d
	return theText_escaped
end escapeSlash

1 Like