API for file access?


#1

Is there an object in the SDK that will provide access to the path of the current file? I would like to be able to insert direct, non-relative references to other files within the editor.


#2

If you use JavaScript for Automation, for example, the file() method of the active document will return a Path object (or null if the current doc has not yet been saved to a specific file).

https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-10.html#//apple_ref/doc/uid/TP40014508-CH109-SW1

function run () {

    var ds = Application("FoldingText").documents(),
        doc = ds.length ? ds[0] : undefined,
    
        
        // null if doc not yet saved, 
        // or a Path() object, if the doc has a file
        file = doc ? doc.file() : undefined;
        
    // convert Path to string for filePath
    return file ? file.toString() : ''
    
}  

#3

Sorry, I was unclear. I’m writing a plugin for FoldingText, not automating it from outside.

As far as I can find, there’s no object that will supply me with the same information that is available to external automation, such as the Application object, or even just the path of the current file.


#4

direct, non-relative references to other files

Presumably something a bit different from this ?

a plugin for FoldingText

Would it work to launch it as a script, passing file path strings into the FoldingText evaluation context through the options object ?

(as, for example in the script below)


#5

Ideally, I’d like to put some markup in the FoldingText document, and upon seeing that markup, have the node rendered into an image by something external. Running an external script (unless you know of a way that a plugin can run a script?) probably isn’t going to get me where I want to be. I’d really prefer to have an object within the plugin context that provides access to metadata about the file being edited, particularly its filename. Even better, I’d like to have the ability to execute external programs/scripts from within the plugin code.


#6

Mutahir would give you a more authoritative view of that, but I think it may not be easy (given sandboxing architecture) for a FoldingText context evaluation of JS to be given access to the filing system.

(Launching your FoldingText context code as a script, rather than a plugin, may simplify and enable a lot of things)