Yeah, application and Mac OS control is difficult and unpredictable in that not all apps have an accessible (AppleScript/Javascript) API (e.g., Scrivener, LiquidText) but though it's more limited, everything can be controlled through simulated mouse clicks & drags using AppleScript, Javascript, and Python (and probably other languages) using "accessibility". I'd prefer to keep as much as possible in Javascript since that's the easiest way to access Zotero locally (I only know AppleScript, Python, Ruby, and a little Swift). In Python I can use PyAutoGUI for this and it works well. There are often also limited commands that can be issued through some language-agnostic, application-specific URIs.
First a comment and then I should explain the broader project goal.
Comment:
"Collections' in Zotero that contain "sub-collections" do not behave intuitively like folders. If I have collection B inside collection A and do a search for an entry that is in collection B but not A while collection A is selected, then I get no results. Collections do not act like containers so sub-collection entries do not show up in searches (unless I'm missing something obvious). I consider this to be counterintuitive enough to be considered a bug (feel free to correct me here).
The Broader Goal:
I've got a Zotero library with all my PDFs stored on DropBox. I know that Zotero storage is the greatest thing since sliced bread and makes collaboration using "Group"s possible but for many of us the Zotero folder structure is a deal-breaker because it imposes a non-human-readable intermediary folder layer between us and the PDFs that we need to access using a variety of different apps (in my case-- PDF Expert, PDF Reader Pro, LiquidText, and sometimes Preview or Skim and others). PDFs are a nightmare of non-standardized properties, libraries, and app features, but that's the default these days so we have to deal with it. Each PDF app has something it can do that others can't so you have to pick each for the job that you need.
Every research project needs a different selection of PDFs organized into various subfolders. And these need to be accessible by my collaborators. I can't re-organize the folder structure of the original PDFs since that would screw up Zotero's links to those PDFs each time if I changed their location constantly. The solution, then, is to use aliases. I can put aliases anywhere and organize them however I want. And my collaborators can easily gain access to the original PDF through the organized folders of aliases.
I might have a Zotero collection, "Fish Paper", with general entries about fish, then a sub-collection called, "Fish Mammals" that contains entries about whales and dolphins, and another sub-collection named, "Aquatic Serpents" with entries about eels and sea snakes. (I'm making this up--I know nothing about marine biology.) The goal is to mirror the Zotero collection and sub-collection structure with the same folder and sub-folder OS file structure filled with aliases of the PDFs from those Zotero collections.
So, I would click on the top-level collection in Zotero--"Fish Paper", a dialog from Zotero would pop-up asking me where I want the mirrored aliases to go, and then a new top-level folder with the same name "Fish Paper" would be created with the subfolders and all the PDF aliases in the right places—the new "Fish Paper" folder would contain all the alias from the PDFs in the Zotero entries for the "Fish Paper" collection. The "Fish Mammals" would contain all the PDF aliases from its entries", an the same for "Aquatic Serpents".
Pseudo-Code:
[Zotero Javascript]
-- repeat for each collection starting at the top: get the name of the collection and a list of all the PDF paths in that collection
(error out if more than one collection has been selected by the user)
[Mac Javascript/AppleScript]
-- repeat for each saved Zotero collection and PDF paths list: create the file folder, create an alias of each PDF using its path, and place the alias in the folder
(if the top-level folder already exists, delete it without asking and rebuild the entire folder tree)
Phase 2--
Watch that top-level Zotero collection and re-run the code whenever there is any change to any part of that collection or anything beneath it. This keeps the Zotero collection (and sub-collections) all in sync with the folder aliases.
My apologies for the lengthy explanation but when I'm coding I find it helpful to have lots of detail.
==============================================================================
I have no idea how to do the Zotero part of the pseudo code. I also have no idea how to set up the combined Javascript/Applescript code so that it can call Zotero. If the two can't be combined, then then the first Javascript script can juts past control to a second AppleScript-only script.
For example, to bring up a dialog selecting a OS folder (in Javascript):
- var app = Application.currentApplication()
- app.includeStandardAdditions = true
-
- var outputFolder = app.chooseFolder({
- withPrompt: "Please select an output folder:"
- })
- outputFolder
- // Result: Path("/Users/yourUserName/Desktop")
Getting a path (in Javascript):
- var path = Path("/Users/yourUserName/Desktop/My File.txt")
- var string = path.toString()
- string
- // Result: "/Users/yourUserName/Desktop/My File.txt"
To make some aliases (in AppleScript):
https://stackoverflow.com/questions/22799334/creating-a-finder-alias-using-applescript
After all that, if someone is still interested :-) let me know. I'm flexible on collaborating, paying for just the Zotero part, paying for the whole thing, or just learning together!
Cheers!