Script to open the current FoldingText file in Brett Terpstra's Marked

Brett Terpstra’s Marked 2 is an excellent adjunct to FoldingText.

As you type and edit in FoldingText, you can watch a stylesheet-formatted version of your text updating every time you save. In addition for formatted printing, and various kinds of export from your FoldingText document (.docx, PDF, RTF etc), it also offers very useful editing tools and a choice of style-sheets.

Here is a script to automatically open a Marked window into the file which you are editing in FoldingText.

property pTitle : "Open FoldingText file in Marked"
property pVer : "0.02"
property pAuthor : "Robin Trew"

property pblnPositionWindows : true -- Set this to false to disable the window positioning at the end of the script

on run
	tell application "FoldingText"
		set lstDocs to documents
		if lstDocs = {} then return
		set {strName, oFile} to {name, file} of item 1 of lstDocs
		if oFile is missing value then
			display dialog "The document: " & return & return & strName & ¬
				return & return & "needs to be saved before Marked can preview it." buttons {"OK"} ¬
				default button "OK" with title pTitle & "  ver. " & pVer
		end if
	end tell
	---- Marked
	tell application id "com.brettterpstra.marky"
		open oFile
	end tell
	-- Try to position windows left and right (to disable this, if it doesn't suit your workflow or your screen setup,
	-- set pblnPositionWindows at the top of the script to false )
	if pblnPositionWindows then
		set lngWidth to word 3 of (do shell script "defaults read /Library/Preferences/ | grep -w Width")
		set lngHeight to word 3 of (do shell script "defaults read /Library/Preferences/ | grep -w Height")
		set lngHalf to lngWidth / 2
		set lngHeight to lngHeight - 22
		tell application id "sevs"
			tell process "FoldingText" to tell window 1 to set {position, size} to {{lngHalf, 22}, {lngHalf, lngHeight}}
			tell process "Marked" to tell window 1 to set {position, size} to {{0, 22}, {lngHalf, lngHeight}}
		end tell
	end if
end run


I had to modify it to work for me. I changed these lines:

	set lngWidth to (do shell script "system_profiler SPDisplaysDataType | awk '/Resolution/{print $2}'")
	set lngHeight to (do shell script "system_profiler SPDisplaysDataType | awk '/Resolution/{print $4}'")

The original lines only say that the domain is not valid. I am using it in a Alfred script and it works nicely. Thanks!

I was trying to make a command in FT for it, but I could not find a way to get to the file name in JavaScript. Is there a way?

Thanks for those lines. Not sure what the system difference is there.

On access to the file system in FT scripts - you need to do that part in Applescript. passing data in to the JS evaluation though key:value pairs in a an Applescript record given to the with options clause of evaluate script ... with options ... and collecting them on the JS side from the options object.

PS may be worth checking whether your system_profiler variant is working OK with dual monitor systems.

On my system the grep version here is returning a single
2560 and 1600 (resolution of the active screen - a monitor attached to my laptop)

While the awk+system_profiler alternative is returning double results (two width values and two height values, each delimited by \r, so that the string to real conversion fails with an error message.

(Should be fine though on single display systems).

I only have a single monitor system. It would be easy to fix the script for processing two outputs, but I have no way to test it. None of my systems will take two monitors.

For new users wondering why this script isn’t working anymore. Brett Terpstra changed the application id from Marked 2:

Deprecated: com.brettterpstra.marky

New: com.brettterpstra.marked2

Make sure to exchange it.

Hi Patrick, are you bumping into this issue with the Aug 11 version ?

Kind of:

The two changes I made:

  1. com.brettterpstra.marked2
  2. tell process "Marked 2"

Also, I had to set pblnPositionWindows to false since window positioning in Yosemite still isn’t working that great most times.

Ah … looks like you’re still using another (earlier) version.

( The Aug 11 (linked above) doesn’t actually use any bundle identifiers )

Good luck with the early adoption : - )


You’re right. I overlooked the link. Now I’ll download the linked version. Sorry.

Updated (a little faster and easier to adjust, with a more general display resolution detection) at: