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.
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
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
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: