Listing all commands and shortcuts (JXA and Applescript versions)


#1

FoldingText has a wealth of commands to which keyboard shortcuts are (and can be) attached.

To get a list of them into the clipboard you can either use OS X 10.10 JXA (JavaScript for Applications):

function run() {

	var fnCmdList = function (ed) {

			var Pasteboard = require('ft/system/pasteboard').Pasteboard,
				arrCmd = ed.commands(),
				lst = [],
				dctCmd, strKey,
				strList;

			for (var lng = arrCmd.length, i = 0; i < lng; i++) {
				dctCmd = arrCmd[i];
				lst.push(
					(strKey = dctCmd.shortcut) ?
					dctCmd.name + '\t' + strKey :
					dctCmd.name
				);
			}
			lst.sort();

			strList = lst.join('\n');
			Pasteboard.writeString(strList);
			return strList;
		},

		docsFT = Application("FoldingText").documents(),
		varResult = docsFT.length && docsFT[0].evaluate({
			script: fnCmdList.toString()
		});

	return varResult;
}

or Applescript (slower and more cluttered but perhaps still more familiar)

property pstrJS : "

function (ed) {
	var arrCmd = ed.commands(),
		lst = [],
		dctCmd, strKey;
	for (var lng = arrCmd.length, i = 0; i < lng; i++) {
		dctCmd = arrCmd[i];
		lst.push(
			(strKey = dctCmd.shortcut) ?
			dctCmd.name + '\\t' + strKey :
			dctCmd.name
		);
	}
	lst.sort();
	return lst.join('\\n');
}

"

tell application "FoldingText"
	set lstDocs to documents
	if lstDocs is not {} then
		tell item 1 of lstDocs to set strCommands to (evaluate script pstrJS)
		set the clipboard to strCommands
		return strCommands
	end if
end tell

FoldingText Extensions Wiki
#2

Thanks. I have just been going through the code. Much harder, but more informative!