Need some AppleScript advice, I have a script that creates/add to a record and then open it in a window. Currently the script open a new window each time it’s called, I would like to check if the record is already open and if that is the case just bring the window to front. In other words, this
open tab for record myRecord
should probably look something like this
if the_window_for_myrecord_is_open then
bring the window to front
else
open tab for record myRecord
but how do I do this??
on create_entry(theYear, theMonthNum, theDay, shortWeekday, theTime, theHeadline, notetext)
tell application id "DNtp"
try
activate
set jsr to (open database "xxx.dtBase2")
set myGroup to create location "/_qqqq/" & "/" & theYear & "/" & theMonthNum in jsr
set recordName to theYear & "-" & theMonthNum & "-" & theDay & " " & shortWeekday
set myRecords to children of myGroup whose name is recordName and type is markdown
if ((count of myRecords) is 0) then -- Create the document from scratch
set theContent to "# " & return & return
set myRecord to create record with {name:recordName, content:theContent, type:markdown} in myGroup
else
set myRecord to item 1 of myRecords
end if
set theContent to plain text of myRecord
set plain text of myRecord to theContent & return & return & "---" & return & return & "## " & theTime & return & notetext
open tab for record myRecord
on error errMsg number errNum
display alert (localized string "An error occured when adding the document.") & space & errMsg
end try
end tell
end create_entry