Skip to content

Using Scripts ​

AppleScript can read and change a WriteRoom document's text and selection.

To see everything WriteRoom understands, choose File > Open Dictionary… in Script Editor, then pick WriteRoom.

What a Script Can Use ​

Documents come from the standard suite, so make, open, save, close, and count work as they do in other Mac apps. WriteRoom adds these properties to each document:

  • text: the document's text
  • selected text: the selected text. Setting it replaces the selection.
  • selection: the selection as {start, end} character offsets
  • id: an identifier that stays the same while the document is open

Examples ​

To read the front document ​

applescript
tell application "WriteRoom"
	get text of front document
end tell

To wrap the selection in quotes ​

applescript
tell application "WriteRoom"
	set theText to selected text of front document
	set selected text of front document to "“" & theText & "”"
end tell

To make a new document ​

applescript
tell application "WriteRoom"
	make new document with properties {text:"Hello, WriteRoom!"}
end tell

See also ​