This helped me quite a bit to get started, thanks!
However, I’ve run into some problems. Building on your example, I assumed I could continue somehow like below. But first of all I want to say: wow, this is tear-jerkingly convoluted with applescript. I’ve never really concerned myself with it though. So please excuse my asking this possibly easy to solve question.
tell application id "DNtp"
set theIndex to ""
set theParsedName to ""
set theSelection to the selection
repeat with thisItem in theSelection
-- here I wanted to intercept the returned name, modify it and only then pass it to theIndex
set theParsedName to (name of thisItem)
on splitName(originalName)
set cutPosition to (offset of "-" in originalName) - 1
return text 1 thru cutPosition of originalName
end splitName
set theParsedName to splitName(theParsedName)
-- With this the name is cut off at the "-"
-- The convoluted decoder
on decodedName(TheString)
set previousDelimiter to AppleScript's text item delimiters
set potentialName to TheString
set legalName to {}
set legalCharacters to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
repeat with thisCharacter in the characters of potentialName
set thisCharacter to thisCharacter as text
if thisCharacter is in legalCharacters then
set the end of legalName to thisCharacter
log (legalName as string)
else if thisCharacter = "ö" then
set the end of legalName to "oe"
log (legalName as string)
else if thisCharacter = "ä" then
set the end of legalName to "ae"
log (legalName as string)
else if thisCharacter = "ü" then
set the end of legalName to "ue"
log (legalName as string)
else if thisCharacter = "Ö" then
set the end of legalName to "Oe"
log (legalName as string)
else if thisCharacter = "Ä" then
set the end of legalName to "Ae"
log (legalName as string)
else if thisCharacter = "Ü" then
set the end of legalName to "Ue"
log (legalName as string)
end if
end repeat
set AppleScript's text item delimiters to ""
if length of legalName is greater than 32 then
set legalName to items 1 thru 32 of legalName as text
else
set legalName to legalName as text
end if
set AppleScript's text item delimiters to previousDelimiter
return legalName
end decodedName
return decodedName(theParsedName)
-- At this point, e.g. "Höffe, Otfried 2004 - Kant's Kritik der reinen Vernunft" is truncated to "HoeffeOtfried2004" and stored in theParsedName
-- This is the version I want to pass into theIndex
set theIndex to theIndex & "\"" & theParsedName & "\": " & "\"" & (uuid of thisItem) & "\"" & return
end repeat
set the clipboard to {text:(theIndex as string), Unicode text:theIndex}
end tell
As a standalone it works fine, but in combination with your example it does not. I reckon the problem is that AS doesn’t allow for this kind of routine to play out WITHIN the tell application id "DNtp"
segment. What I’m proped with is this:
expected “end”, but found “on”.
(“end” erwartet, aber “on” gefunden.)
This makes things even more complicated. Do you see my problem? I want to modify the name before it is passed into the collection theIndex (simple string, array, list?). To filter a text file for each individual line, modify just the name but leave everything else untouched – I wouldn’t even know how to start with that ad hoc… pandoc pipes maybe
Anyway, this shouldn’t be so hard, right? Do you know of an easy fix or have a suggestion for me how to proceed?
Sure, once everything checks out nicely I’ll post it in the DTTG section