Public Access
Initial commit: v1.4 with documentation
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
tell application id "DNtp"
|
||||
set monthNames to {"01_Januar", "02_Februar", "03_MŠrz", "04_April", "05_Mai", "06_Juni", "07_Juli", "08_August", "09_September", "10_Oktober", "11_November", "12_Dezember"}
|
||||
|
||||
set monthVariants to {"januar", "jan", "january", Â
|
||||
"februar", "feb", "february", Â
|
||||
"mŠrz", "maerz", "mrz", "mŠr", "march", "mar", Â
|
||||
"april", "apr", Â
|
||||
"mai", "may", Â
|
||||
"juni", "jun", "june", Â
|
||||
"juli", "jul", "july", Â
|
||||
"august", "aug", Â
|
||||
"september", "sep", "sept", Â
|
||||
"oktober", "okt", "october", "oct", Â
|
||||
"november", "nov", Â
|
||||
"dezember", "dez", "december", "dec"}
|
||||
|
||||
set selRecs to selection as list
|
||||
if (count of selRecs) is 0 then
|
||||
display dialog "Bitte einen Ordner in DEVONthink auswŠhlen." buttons {"OK"} default button "OK"
|
||||
return
|
||||
end if
|
||||
|
||||
set targetGroup to first item of selRecs
|
||||
set targetName to name of targetGroup
|
||||
|
||||
set normalizedTargetName to my normalizeMonthFolderName(targetName)
|
||||
if monthVariants contains normalizedTargetName then
|
||||
set answerButton to button returned of (display dialog "Du stehst im Ordner " & targetName & ". Willst du hier trotzdem einen Jahreszyklus anlegen?" buttons {"Abbrechen", "Ja"} default button "Ja" with icon caution)
|
||||
if answerButton is "Abbrechen" then return
|
||||
end if
|
||||
|
||||
repeat with i from 1 to count of monthNames
|
||||
set monthName to item i of monthNames
|
||||
try
|
||||
create record with {name:monthName, type:group} in targetGroup
|
||||
end try
|
||||
end repeat
|
||||
|
||||
try
|
||||
create record with {name:"Versendet", type:group} in targetGroup
|
||||
end try
|
||||
|
||||
display dialog "Fertig." buttons {"OK"} default button "OK"
|
||||
end tell
|
||||
|
||||
on normalizeMonthFolderName(theName)
|
||||
set t to (do shell script "printf %s " & quoted form of theName & " | tr '[:upper:]' '[:lower:]'")
|
||||
set t to my replaceText(".", "", t)
|
||||
set t to my replaceText("_", " ", t)
|
||||
set t to my replaceText("-", " ", t)
|
||||
set t to my trimText(t)
|
||||
try
|
||||
set t to do shell script "printf %s " & quoted form of t & " | sed -E 's/^[0-9]{1,3}[[:space:]]+//; s/^[0-9]{1,3}//'"
|
||||
on error
|
||||
-- falls sed zickt, einfach Original weiterverwenden
|
||||
end try
|
||||
set t to my trimText(t)
|
||||
return t
|
||||
end normalizeMonthFolderName
|
||||
|
||||
on replaceText(findText, replaceWith, sourceText)
|
||||
set AppleScript's text item delimiters to findText
|
||||
set textItems to every text item of sourceText
|
||||
set AppleScript's text item delimiters to replaceWith
|
||||
set newText to textItems as text
|
||||
set AppleScript's text item delimiters to ""
|
||||
return newText
|
||||
end replaceText
|
||||
|
||||
on trimText(t)
|
||||
set whitespaceChars to {space, tab, return, linefeed}
|
||||
repeat while t is not "" and (character 1 of t is in whitespaceChars)
|
||||
set t to text 2 thru -1 of t
|
||||
end repeat
|
||||
repeat while t is not "" and (character -1 of t is in whitespaceChars)
|
||||
set t to text 1 thru -2 of t
|
||||
end repeat
|
||||
return t
|
||||
end trimText
|
||||
Reference in New Issue
Block a user