Listing all opened documents across all open visible apps in AppleScript
I’ve been trying to do this myself. I have concluded that there is no standard, guaranteed way to get the open documents of a running application.

What you tried is the best method. For apps that use the Cocoa document architecture (the majority), there is automatic AppleScript support for getting all the open NSDocument objects and querying certain properties of those objects. The mapping between the AppleScript properties and the Objective-C properties is shown below.

AppleScript property => Objective-C getter:


path => fileName
modified => isDocumentEdited
name => lastComponentOfFileName


What you want is the path property. Like tell application "Preview" to set documentsList to path of documents.

Unfortunately, this automatic AppleScript support is only available for apps that use the Cocoa document architecture and have AppleScript enabled (via the NSAppleScriptEnabled Info.plist key). Therefore, this method will not work on some apps. For example, CodeRunner does not have AppleScript enabled. And TextMate does not use the Cocoa document architecture.