local metadataRecord
set metadataRecord to create record with {name:"metadata.tex", |type|:"txt", content:theContent, tags:{globalIgnoreTag}} in selectedGroup
-- set name of metadataRecord to "metadata.tex"
This results in metadata.tex.txt, but I would like to see metadata.tex. Sorry to ask, but I was not able to achieve this. ![]()
Here’s the full script, but I think the snippet above might be enough to understand what I want to do.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
use script "Dialog Toolkit Plus" version "1.1.3"
use script "RegexAndStuffLib" version "1.0.7"
property globalIsDev : true
property globalIgnoreTag : "ignoriere-datei"
tell application id "DNtp" to my main(selected records, globalIgnoreTag)
on main(selectedGroup, ignoreTag)
verifyParameter(selectedGroup)
set selectedGroup to item 1 of selectedGroup
local pathMetadataRecord
set pathMetadataRecord to my getPathExistingMetadataPlist(selectedGroup)
local theContent
set theContent to my plistToTexFileContent(selectedGroup, pathMetadataRecord)
my createMetadataFile(selectedGroup, ignoreTag, theContent)
end main
on verifyParameter(selectedGroup)
if length of selectedGroup > 1 then
my dtLog(missing value, "ERROR", quoted form of "Only selection of single group is allowed", {"count=" & length of selectedGroup})
error "Only selection of single group is allowed"
end if
set selectedGroup to item 1 of selectedGroup
tell application id "DNtp"
if record type of selectedGroup is not group then
my dtLog(missing value, "ERROR", quoted form of "Only selecting a single group is allowed", {"record-type=" & record type of selectedGroup})
error "OOnly selecting a single group is allowed"
end if
end tell
end verifyParameter
on createMetadataFile(selectedGroup, ignoreTag, theContent)
tell application id "DNtp"
local metadataRecord
set metadataRecord to create record with {name:"metadata.tex", |type|:"txt", content:theContent, tags:{ignoreTag}} in selectedGroup
-- set name of metadataRecord to "metadata.tex"
local metadataRecordLocation
set metadataRecordLocation to (location with name of metadataRecord as string)
my dtLog(metadataRecord, "DEBUG", quoted form of "Created metadata TeX file", {"location=" & quoted form of metadataRecordLocation, "filename=" & quoted form of (filename of metadataRecord as string)})
end tell
end createMetadataFile
on getPathExistingMetadataPlist(selectedGroup)
local pathMetadataRecord
tell application id "DNtp"
local metadataRecord
set metadataRecord to item 1 of (search "extension==plist name:metadata" in selectedGroup)
if metadataRecord is missing value then
my dtLog(missing value, "WARN", quoted form of "No metadata.plist found in group", {"location=" & quoted form of location of selectedGroup, "group=" & quoted form of name of selectedGroup})
return
end if
set pathMetadataRecord to path of metadataRecord as string
end tell
return pathMetadataRecord
end getPathExistingMetadataPlist
on joinWithComma(elements)
return join strings elements using delimiter ", "
end joinWithComma
on plistToTexFileContent(theGroup, plistPath)
local plistExists
set plistExists to (do shell script "test -f " & quoted form of plistPath & " && echo 'yes' || echo 'no'") is "yes"
my dtLog(theGroup, "DEBUG", quoted form of "Test for existence of plist metadata file", {"path=" & quoted form of plistPath, "result=" & plistExists as text})
if plistExists is false then
return
end if
local theAuthors, theVersion, theDate
tell application "System Events"
tell property list file plistPath
set theAuthors to my joinWithComma(value of property list item "authors")
set theVersion to value of property list item "version"
set theDate to value of property list item "date"
end tell
end tell
local theContent
set theContent to "\\newcommand{\\docversion}{" & theVersion & "}
\\newcommand{\\doclastedit}{" & theDate & "}
\\newcommand{\\docauthors}{" & theAuthors & "}
"
return theContent
end plistToTexFileContent
on dtLog(theRecord, level, msg, msgInfo)
if class of msgInfo is not list and msgInfo is not missing value then
error "Invalid definition of msgInfo in dtLog: Needs to be {}"
end if
if msgInfo is missing value then
set logMsg to "msg=" & msg
else
set logMsg to "msg=" & msg & " " & (join strings msgInfo using delimiter return)
end if
if level is not "DEBUG" then
tell application id "DNtp"
if theRecord is missing value then
log message "level=INFO " & logMsg
else
log message record theRecord info "level=INFO " & logMsg
end if
end tell
return
end if
if globalIsDev is true then
tell application id "DNtp"
if theRecord is missing value then
log message "level=INFO " & logMsg
else
log message record theRecord info "level=INFO " & logMsg
end if
end tell
end if
end dtLog