Convert every file whose kind is “Mariner Write document”


HumanPotential
Robert McGarey

6m

I like Mariner Write, but it no longer works on newer machines and I need to upgrade soon. I have 1,300 Mariner Write documents that I want to convert (probably to rtf) so I don’t lose access when I upgrade.

I have thought of writing some recursive script to walk all the folders, but I think it would be easier to get a list of all 1,300 file/folder locations and tell Mariner Write to convert each one that way.

Suggestions?

What is the latest OS it runs on?

@HumanPotential
There is at least 3 good ways with acceptable performance.

  1. To use AppleScriptObjC and the class NSFileManager (Objective-C)
  2. Use AppleScript’s System Events to get the contents from folder
  3. Use do shell script to use unix shell (bash)

Avoid Finder because its slow and AppleScript filter.

If you search in the forum you could find the code you need.

Is you approach to open document 1 and export to rtf and repeat this process to all document is exported??

"Effective with the release of Catalina (10.15), Mariner Software has ended development of Mariner Write. " – from the developer

Yes, I’m planning to convert documents one at a time until they are all converted. I’m “old school” and haven’t yet used AppleScriptObjC and don’t do UNIX hardly ever. However, I suppose there’s no harm in learning…

I know how to script Mariner Write. What I would like would be a text file that lists the full file location of every document, so that AS could then take the first line and convert that file, then take the second line and convert it, and so on.

The following script should do what you want. It may seem needlessly complex, but it will do the job quickly and reliably and only needs to be run once. Before running this script, change the file extensions to those that apply to Mariner Write. A text file will be created on your desktop.

The text file returns Posix paths. If HFS paths are required in your Mariner Write conversion script, simply use “POSIX file” (no quotes) before the file path.

use framework "Foundation"
use scripting additions

set theFolder to POSIX path of (choose folder) -- select top-level folder that contains the files
set fileExtensions to {"txt", "pdf"} -- set to desired file extensions
set theFiles to getFiles(theFolder, fileExtensions)
writeFile(theFiles)

on getFiles(theFolder, fileExtensions)
	set fileManager to current application's NSFileManager's defaultManager()
	set theFolder to current application's |NSURL|'s fileURLWithPath:theFolder
	set folderContents to (fileManager's enumeratorAtURL:theFolder includingPropertiesForKeys:{} options:6 errorHandler:(missing value))'s allObjects()
	set thePredicate to current application's NSPredicate's predicateWithFormat_("pathExtension.lowercaseString IN %@", fileExtensions)
	set theFiles to (folderContents's filteredArrayUsingPredicate:thePredicate)
	set descriptorOne to current application's NSSortDescriptor's sortDescriptorWithKey:"stringByDeletingLastPathComponent" ascending:true selector:"localizedStandardCompare:" -- sort by path of containing folder
	set descriptorTwo to current application's NSSortDescriptor's sortDescriptorWithKey:"lastPathComponent" ascending:true selector:"localizedStandardCompare:" -- sort by file name
	return ((theFiles's valueForKey:"path")'s sortedArrayUsingDescriptors:{descriptorOne, descriptorTwo})
end getFiles

on writeFile(theFiles)
	set theString to theFiles's componentsJoinedByString:linefeed
	set theFolder to (current application's NSHomeDirectory()'s stringByAppendingPathComponent:"Desktop")
	set theFile to theFolder's stringByAppendingPathComponent:"Mariner Write Files.txt"
	theString's writeToFile:theFile atomically:true encoding:(current application's NSUTF8StringEncoding) |error|:(missing value)
end writeFile

Does that mean it won’t work on Catalina, or Catalina is the last OS it will work on?
It seamed a little ambiguous to me.

@robertfern
The software that the OP is using is only 32-bit. To use Catalina or mordern hardware its not possible (at least in normal use) to execute 32-bit application.

That said I have read on random location a user could remove SIP protection and next reboot with kernel parameters. set the DYLD_LIBRARY_PATH before execution are able to run 32-bit app beyond Catalina. It means a machine with 32-bit library need to be transfer to 64-bit OS machine.

I have not test this myself.

Here is different approach from an test of 13956 paragraphs in less and 1 second.

use framework "Foundation"
use scripting additions

set folderPath to POSIX path of (choose folder)
set savePath to POSIX path of (path to desktop) & "Mariner Write Files.txt"
set saveURL to current application's |NSURL|'s fileURLWithPath:savePath

set fileManager to current application's NSFileManager's defaultManager()
set theEnumerator to (fileManager's enumeratorAtPath:folderPath)'s allObjects()
set thePredicate to current application's NSPredicate's predicateWithFormat_("pathExtension.lowercaseString IN %@", {"txt"})
set filteredObjects to (theEnumerator's filteredArrayUsingPredicate:thePredicate)

set theString to current application's NSMutableString's alloc()'s init()
repeat with fileObject in filteredObjects
	theString's appendFormat_("%@", (folderPath & fileObject) & linefeed)
end repeat
theString's writeToURL:saveURL atomically:true

The Predicate filter use the extension txt you need to change that to your document extension. The save path of the file is Dekstop folder.

If HFS paths are required and sorting is not, the following can be used. The timing result with a folder than contained 837 files in 179 folders with 663 matching files was 79 milliseconds, so this script should work on an older computer.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set theFolder to POSIX path of (choose folder) -- select top-level folder that contains the files
set fileExtensions to {"txt", "pdf"} -- set to desired file extensions
set theFiles to getFiles(theFolder, fileExtensions)
writeFile(theFiles)

on getFiles(theFolder, fileExtensions)
	set fileManager to current application's NSFileManager's defaultManager()
	set theFolder to current application's |NSURL|'s fileURLWithPath:theFolder
	set folderContents to (fileManager's enumeratorAtURL:theFolder includingPropertiesForKeys:{} options:6 errorHandler:(missing value))'s allObjects()
	set thePredicate to current application's NSPredicate's predicateWithFormat_("pathExtension.lowercaseString IN %@", fileExtensions)
	set theFiles to (folderContents's filteredArrayUsingPredicate:thePredicate)
	set hfsPaths to current application's NSMutableArray's new()
	repeat with aURL in theFiles
		(hfsPaths's addObject:(aURL as text))
	end repeat
	return hfsPaths
end getFiles

on writeFile(theFiles)
	set theString to theFiles's componentsJoinedByString:linefeed
	set theFolder to (current application's NSHomeDirectory()'s stringByAppendingPathComponent:"Desktop")
	set theFile to theFolder's stringByAppendingPathComponent:"Mariner Write Files.txt"
	theString's writeToFile:theFile atomically:true encoding:(current application's NSUTF8StringEncoding) |error|:(missing value)
end writeFile

@peavine
If you use the NSResourceKey NSURLPathKey you only need to convert every object in the list to string. And you will get HFS path. It maybe are faster I do not know.

ex.

use framework "Foundation"
use scripting additions

set folderPath to POSIX path of (choose folder)
set savePath to POSIX path of (path to desktop) & "Mariner Write Files.txt"
set saveURL to current application's |NSURL|'s fileURLWithPath:savePath

set fileManager to current application's NSFileManager's defaultManager()
set folderURL to current application's |NSURL|'s fileURLWithPath:folderPath
set theEnumerator to (fileManager's enumeratorAtURL:folderURL includingPropertiesForKeys:{current application's NSURLPathKey} options:6 errorHandler:(missing value))'s allObjects()
set thePredicate to current application's NSPredicate's predicateWithFormat_("pathExtension.lowercaseString IN %@", {"txt"})
set filteredObjects to (theEnumerator's filteredArrayUsingPredicate:thePredicate)

set theString to current application's NSMutableString's alloc()'s init()
repeat with fileObject in filteredObjects
	theString's appendFormat_("%@", (fileObject as string) & linefeed)
end repeat
theString's writeToURL:saveURL atomically:true

I tested and the timing results for both scripts were identical. Two slightly different approaches that accomplish the same thing.

Yes, it is ambiguous. It could even mean that it can work on an OS greater than Catalina, but that the developer won’t guarantee the results. I only know that it does work on OS 10.13.8.

These scripts look great, so I think we are almost there. The remaining problem is that many or most of my Mariner Write documents don’t have an extension, they are simply Mariner Write documents. It’s not that the extension is hidden; the extension does not exist. So we’ll have to search by “kind = Mariner Write document” or some such.

Here’s an example of the fact of some documents not having an extension. Two documents of the same name at the same location, one with an extension and one without:


Hi,
or a shell one liner:

find -E ~/Documents \( -regex '.*.pdf' -or -not -regex '.*/.*\.[a-z0-9]{2,20}' \) -and  -type f  -exec file {} ';' | awk -F":" '/PDF/{print $1}'>myFileList.txt

I assume you have the files in ~/Documents and subfolders, else you need to state the top directory.
Exchange pdf with mwd and /PDF/ with /Mariner/
BR