Daily journal script on markdown returns

Hey!

I’ve been using a custom version of the “Daily Journal Script - Markdown” to keep track of something. However, I just realize that when I try to transform the markdown files with Pandoc something wasn’t playing well and all the text ended up in the same line. After a lot of trial and error I figured out that the problem was the “returns” that the apple script had on body of the future text. Like in the below chunk.

tell application id "DNtp"
	try
		activate
		set myGroup to create location "/Journal/" & "/" & theYear & "/" & numMonth
		set recordName to theYear & "-" & numMonth & "-" & 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
			if my theLocale is "de" then
				set theHeadline to (longWeekday & "," & space & shortDay & "." & space & theMonth)
			else
				set theHeadline to (theMonth & space & shortDay & daySuffix & "," & space & longWeekday)
			end if
			
			set myQuote to my getQuote()
			set myNews to my getNews()
			set theContent to "# " & theHeadline & return & "<i>" & myQuote & "</i>" & return & return & "# Headlines" & return & return
			
			repeat with i from 1 to (count of items of myNews) by 2
				set theContent to theContent & "[" & item i of myNews & "]"
				set theContent to theContent & "(" & item (i + 1) of myNews & ")   " & return
			end repeat
			
			set myRecord to create record with {name:recordName, content:theContent, type:markdown, tags:theYear & "," & theMonth} in myGroup
		else -- Record already exists, just add new weather/time header
			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 & "## " & theTime & return & "- "
		
		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

It seems that those returns end on a weird format / character and unless you open and save the file with an additional app related to markdown, like Typora, the issue is not corrected. I usually use Sublime Text to edit, but the problem persisted with it and there was no hint that the carriage return wasn’t formatted properly.

Changing the returns for "\n", the problem disappeared. However, I don’t know if there is a better way or more elegant way to introduce a carriage return / end of the line on apple script.

Use linefeed

1 Like

Hey!

Thanks!! That works!

1 Like