Let’s say I select some text from a webpage, right click, go to Services, and select one of the Scrivener options. I’m wondering just where these services are stored. While they are useful, they don’t bring in the URL (website address), which makes these services a lot less useful because I have no idea where I got this imported text from.
I’m looking for these services because I would like to adapt them so that they import the URL when I invoke the service, instead of having to remember to go back to the webpage, copy the URL, and return to Scrivener to paste the URL.
Services are a part of the software itself (when distributed as a part of software that is, rather than as stand-alone utilities). Even if you could find them inside of the application bundle, they would be compiled code. That aside, We have looked into this before, I know some programs managed to scour the originating URL from compliant web browsers (to be clear, not all work), but it wasn’t obvious how this is being done, in Apple’s documentation for how to code these things.
OK, well that’s a bit of a surprise. I used a combination of Automator and Applescript to do exactly this when working with another program. It would not work in Opera, but considering that most Mac users use either Safari or a Chrome based browser, that was a compromise I was comfortable with.
So the next question would be. Is Scrivener scriptable? If so, I could probably cobble together my own Automator workflow to accomplish this on my own.
AppleScript (which Automator is a subset of with a GUI) may have techniques not available to Cocoa for whatever reason. I think it is silly that this isn’t easy to do with Cocoa, as well. Regarding scripting, unfortunately Scrivener doesn’t have an AppleScript dictionary (one of those things we’ve always wanted to do, but other stuff ends up with higher priorities). You can still automate software to a degree, mostly by triggering menu commands. For example you could create a new text file in the active project binder, trigger Ctrl-Tab paste the clipping in (perhaps inject the URL into the text below it), then use the Move To menu architecture to drop the file into a standard location of your choosing. “Research” would be safest, but if you create a “Clippings” or “Inbox” folder in your binder, you could just as well trigger that as the target.
References would be a better place to stash the originating URL, but I’m not sure if there is a way to even access that level of the UI with AppleScript. There is keyboard or menu access for creating a new external link.
Do you even need Scrivener to be scriptable to accomplish what you want though?
If you have an Applescript (definitely doable) that grabbed your text plus URL and put it on the clipboard, that would pretty much do it, right? If you have your Scriv scratch pad open, for example, you are then ready to paste.
I’m trying to setup Scrivener to be used by lawyers for repetitive client document creation (and filling in names and addresses, etc). Not the most elegant use, but it’s doing many of the things we would like it to do. But having to teach the lawyer how to setup and navigate the initial document each time is beginning to cause problems. If Scrivener were scriptable, a lot of these new-document setup problems could be avoided because I could choose the initial template and setup the different views automatically via a script and just let them worry about the law-stuff and not the computer stuff. (It is what they hired me for…) Any thoughts? Is it on the roadmap at all at this point?
I’m sorry to say that adding AppleScript support is off the roadmap at this point. Not because I don’t think it would be useful - it would. It’s off the roadmap purely because it’s not practical in terms of how much work and upkeep it would take for a single developer given the number of users that might benefit from it. Scrivener is such a huge app that adding AppleScript support that could trigger all of the features users might conceivably want to access would take months of work, and then each time a feature changed or was added, the AppleScript side of things would need updating. It’s not that I’m workshy - I work 12 hours a day or more five days a week on Scrivener and take few holidays (I’m not complaining - I enjoy it) - it’s just that given everything else on the table I can’t see any point where I’m going to get the time to put everything aside for it, let alone the time to update it as I add other features.
What exactly are you trying to achieve, though? Is this not something a Scrivener project template could do?
Thanks for the response-- sorry for the delay in seeing it. I can understand that. My use is probably pretty unusual. I’m helping to automate the creation of Legal documents. I’d like for the lawyer in question to have to remember as few fiddly details as possible in the templates I make for them. (Fiddly details like where to click to fill in the custom meta tags [which contain client information that needs to go into 100 different places in the documents], how to hide the custom meta tags when done, etc.)
I actually hit a lot of walls using AppleScript for the things it can do (at least in theory), so I’m trying out Keyboard Maestro for the job. But there are a few things that it just can’t do without user intervention. Things like select the correct template, or put the cursor into the custom meta-tag fields because those can’t be navigated to with the keyboard or menu. Then the Lawyer has to read a message, and do the fiddly navigation, then get mad at me about it… Basically, the things they have to do become almost as fiddly as the steps I’m trying to save them from doing.
There are some options to consider, particularly if you don’t mind placeholder codes in the text. It is possible to insert nearly every type of meta-data into the text editor with placeholder codes. Many are called by name, such as <$status>. The <$custom:name_of_field> placeholder code does what you would expect: prints the value of the field when you compile, replacing the placeholder. I suppose the main question is whether these fields are used while keying in other data, or if they are in a boilerplate section that doesn’t really need to be edited now that it is dynamic.
If that doesn’t work, you may still be able to do what you want with automation. Since you are messing with Keyboard Maestro, I use that to automate Scrivener a bit, and one of my scripts sounds a good deal like what you are wanting to do. The program is quite navigable with the keyboard. It’s loaded with shortcuts for moving the cursor around in the project window, for example, which is what we need to do much automation. It is a bit fragile. If you change meta-data fields or their order, or how they are entered into documents, you have to build the script again. But it saves me enough time that I don’t mind doing that.
It is possible to select meta-data fields with the keyboard. The View/Inspect/ menu has shortcuts for revealing and activating (on the second shortcut trigger) any Inspector pane (in the case of the meta-data pane, the focus goes to the fields, other panes focus other common areas—you can even insert keywords via scripts). Use UpArrow to select the top field, DownArrow for bottom field. Tab and Shift-Tab navigate between tabs. Combined with KM’s multi-register clipboard capability, you could gather all of the data from the document, however you do that, store them into registers, and then paste and tab down through the list, finishing it off with closing the Inspector.
I’m not sure what you mean by selecting the correct template. There may be a way of doing that too though.
My usage is very simple, so while I’m doing what you want, I don’t know how well it would scale to hundreds. I just have a couple of fields I push over to custom meta-data for the outliner columns.