AppleScript: what do you want to see in the Scrivener Suite?

I would expect that Pages would have the best AppleScript support given that it is written by Apple themselves. :slight_smile: The trouble is that Pages isnā€™t really comparable to Scrivener, as Scrivener isnā€™t a straight word processor. There are a thousand other commands you would need to control the binder and stuff tooā€¦

Iā€™m hoping to look more at AppleScript support after the next update, though.

All the best,
Keith

Think of Applescript as a way to automate multiple applications and youā€™ve got what you need to add as a minimum. For example, I think of Applescript more in terms of what I want to DO than what functionality a specific application would have. One I know what I want to do, then I can determine what to add to an application.

For example:

  1. Iā€™d like to be able to automate the whole process of collecting and moving a draft into a word processor and them imposing some standard template to it for my publisher. On the Scrivener side, Iā€™d need to be able to select all of the draft documents, assemble them, then export them (Iā€™m assuming I understood all this in the tutorial, so forgive my ignorance if Iā€™ve got something wrong). You can see the need ā€¦ one the file exists, Applescript can handle the rest from there as long as my target application can handle the other parts.

  2. Iā€™d like to be able to automate producing a sample chapter as part of a proposal so I can collect all the stuff I need to get to an agent or publisher formatted appropriately. Again, the formatting can be handled by the Word Processor or layout program, thatā€™s not your issue, but choosing the draft elements, assembling them, and passing them out to the word processor are your parts.

  3. Iā€™d like to be in a word processor or online web surfing or somewhere else and be able to hit run a script that would take some element (say a web page) and insert it into a Scrivener project under the appropriate research heading without having to run Scrivener directly. Apple script will allow me to automate things like that if the applications Iā€™m using allow it.

Hereā€™s a specific task Iā€™d like to be able to do with Applescript.

With text selected, 1. copy the selection, 2. create a new document in a folder called Cuts, 3. paste the selected text in the new document, 4. set the synopsis of the new document to the first 20 words of the selected text, 5. delete the selection from the source document.

I do this all the time with stuff that I want to cut but keep around - it would be great to automate it. Steps 1, 3, and 5 are all doable with Applescripts core language features. So whatā€™s needed from Scrivener is a way to create the new document and make its body and synopsis available as a target for pasting, and to switch back to the source document.

Thatā€™d be awesome!

What Derick said. Good idea.

ps

Actually, you do not have the ability to do step 3 via Applescript unless you mean invoking the menu Paste function. But you would not want to have to do that in your script (because it means changing what is in an editor window, etc.). Rather, you would just want the ability to get and set the contents of a documentā€™s body and synopsis.

Another, related application would be to loop through every folder and document within a source folder, and create a corresponding empty folder in a new folder.

e.g. one could start with

Drafts
ā€¦intro
ā€¦body
ā€¦part one
ā€¦part two
ā€¦conclusion

run the script on it and create a new folder hierarchy with a root folder Cuts

Cuts
ā€¦intro
ā€¦body
ā€¦part one
ā€¦part two
ā€¦conclusion

Alternatively the actual program flow could be to duplicate the source, then set the text of each document/folder in the target to be blank.

To accomplish these sorts of tasks in Applescript all that would need to be supplied in the Applescript Suite by the application is the ability to get and set the contents of documents together with the ability to interrogate the binder list and create new folder/docs in it.

From the Suite perspective, this is just to supply language for addressing oneself to the basic scrivener objectsā€“no scrivener-specific functions would yet be involved.

I guess making an app Applescriptable can be hairy, but when Applescriptability comes to Scrivener, the kinds of procedures you are imagining require only basic access to Scrivener objects, it seems pretty well assured they would be possible.

ā€“Greg

Hereā€™s another problem Iā€™d like to solve with Applescript. I have a document in which footnotes are currently in the text, with FN: at the start of the paragraph. Iā€™d like to loop through each paragraph in the document, and if it begins with FN:, delete the text FN: and convert the paragraph to a Scrivener footnote.

More food for thought.

And another. I am setting up a project with a series of numbered documents (1.1, 1.2, 2.1, 2.2 etc., representing weeks of term/classes per week) and would love to be able to write a script (which would be more-or-less for x=1 to 15; for y=1 to 2; create a new document with name x,y; end for; end for) to create the documents.

Why not just use the existing counter tokens for that? <$n> will give you your week number and <$sn> the class number. <$sn> is linked to <$n> in that it will count up until the next instance of <$n> and then resets to 1.

I want to do something rather simple with AppleScript. At least I thought it was simple until I saw that Scrivener doesnā€™t support AppleScript.

I want to take notes from the web and get them into Scrivener, but with more information saved than a Clipping. And easier and faster than Services.

I want to select some text in the browser and create a new document in Scrivener with the title set to the first few words, the text in the body, all or some part in the synopsis, and the url in the references.

Here is a sample Applescript for OmniWeb and DevonThink doing something similar:

	set this_url to address of browser 1
	set this_selection to do script "unescape(getSelection())" window browser 1
	set this_title to the name of browser 1
	
	tell application "DEVONthink Pro" to create record with {name:this_title, type:txt, URL:this_url, plain text:(this_selection & return & return & this_url)} 

So for Scrivener, all I need is to be able to create a document and set the various properties.

Another thing I though of doing with AppleScript:
Go through all the documents or selected documents and if there is no synopsis, set the synopsis to the text or the first few words.

I have a lot of notes and Iā€™d like to organize them using the cork board, but they donā€™t have synopses.

Thanks,
Linda

@Amber - I want the count in the document names in the binder, not in the text itself. The counters donā€™t work there, do they?

Another task

  1. parse a bibliography in Harvard format, e.g.

Barrett, S. R., Stokholm, S., and Burke, J.
2001 The Idea of Power and the Power of Ideas: A Review Essay. American Anthropologist 103(2):468-480.
Barth, F. and others
1969 Ethnic groups and boundaries. : Waveland Press Prospect Heights, Illinois.
Berman, B. J.
1990 Control and Crisis in Colonial Kenya: The Dialectic Of Domination. Athens: Ohio University Press.

(this is fairly easy to do with a text search with regular expressions)

  1. put each item in the bibliography into a separate document in Scrivener

  2. set each documentā€™s synopsis to the first few lines of its text

I have been finding Scrivener, especially the index card view, a great tool for designing course syllabi, where one needs to be able to get an overview of the whole course, tag themes that will reoccur week-to-week, move readings around easily, &c. As I think I said above, opening up Scrivener document attributes and the binder to Applescript would make it possible for users to add bibliographic integration features that would just make it even better for these purposes.

Thanks for all the feedback.

Just for the record, itā€™s highly unlikely that Scrivener will be getting AppleScript support any time soon. Itā€™s a big job and low down on the list - certainly it wonā€™t be making 1.5. It is still slated for a distant future release, though!

Thanks and all the best,
Keith

I do find Scrivener to be most excellent indeed. It is great that the programmer is so helpful and responsive on these forums. I know that I would find the endless requests for this and that to get quite trying :slight_smile:

However this thread brings me to my biggest single critiscism of Scrivener which is the lack of AppleScript support.

The last project I did almost entirely within Scrivener and so lack of AppleSript wasnā€™t a problem. My next series of projects is going to have a great deal more research materials and for that I will be using DEVONthink and DEVONagent.

The workflow is going to be:

Research: DEVONagent DEVONthink
Writing: Scrivener
Prettyfication of output: Pages

Although I havenā€™t started I already know that using scripts to take selected materials from DEVONthink to Scrivener would be very handy. At present Iā€™m not sure how that is going to work out so it is not possible to answer the basic question of the thread. In a few months I will be able to have useful thoughts about how the ideal Scrivener suite would look for me anyway.

A great thing about AppleScript support is that it is useful to people far beyond those that like to write the scripts themselves. AppleScripts could be uploaded to a ā€œScrivener AppleScript bankā€ and downloaded by those who donā€™t script to try out.

Also an AppleScript forum for Scrivener included in this phpBB forum would mean that people who donā€™t script or need help with it could post their questions and there are always many who do like to script who love to answer these things.

I know of course that AppleScript support could not happen by 1.5. However it is looking like 1.5 is going to contain a lot of excellent things :slight_smile:

Sorry to hear that Applescript support isnā€™t coming soonā€¦looking forward to it whenever it does arrive though.

Patrick - one solution Iā€™ve found (specifically to the bibliographic task I described above) is to use a scriptable program to create rtfs which can then easily be imported to Scrivener en masse. Specifically, I wrote an Applescript that uses BibDesk and TextEdit to create individual named .rtfs for each reference, which I can then drag into Scrivener to get the same results I described.

Same approach would work with some of the folder creation tasks I described above, actually - write an Applescript for the Finder to set up the folders, then drag these folders into Scrivener.

Hi Derick

I think that is very likely the route I will be taking. I can get DEVONthink to compile an output to RTF then import for example.

The plan for this project which Iā€™ve now started (while all around me wiser people are munching mince pies) is to keep a total bibliographic database, probably in Bento. In that Bento database then I have a field for all aspects of the Harvard reference style which Iā€™ll be using as well as many other aspects of each book. At the end of the project I can output from that to BBEdit very likely to do some RegEx removal of the database artifacts. This will then go straight to Pages to be included in the final document.

The last project I did I used OmniOutliner for keeping bibliographic record then exported that to be included in the Pages final document.

Iā€™m not in the habit of keeping bibliography in Scrivener.

The reason for using Bento for the new project is its size. It will take four years although there are many spin off things to be produced along the way. So, I want a master database which will keep a lot of books and allow me to select those for final bibliography as well as for smaller bibliographies along the way.

Patrick,

For a bibliographic database of the type you describe, you need to use either EndNote or BookEnds. The main reason these are useful is the styling of output types, namely your footnotes and bibliographies in either articles or chapters. No matter how much input Bento can accept, I doubt it can give you output in the hundreds of styles available in a bibliographic manager. They will also search library and other online catalogs for you and download selected references, saving you hours of typing. See the numerous references on this forum to bibliography and footnotes for more information.

D.

With Endnote, it is also easy to insert with Endnote calls ā€œtemporary citationsā€. Later, when you compile your draft from Scrivener, you can take the result into Word and post process with Endnote into any bibliographic style you like ā€“ or Endnote will operate directly on rtf files, too.

You should definitely not do work to create your own customized bibliographic database from scratch. Believe me, I have been there: I had a pretty good solution going long ago before there was an Endnote, but Endnote quickly supplanted my roll-your-own system.

ā€“Greg

P.S. You might want to search these forums for discussion of citations and bibliographic software. If you search for ā€˜Endnoteā€™, you should find somewhere a detailed description of how I use Endnote with Scrivener.

Thanks druid and gr for putting me back in the way of thinking about Endnote :slight_smile:

In the past when Iā€™ve checked it out Iā€™ve always dismissed it for what I was doing but it might be very suitable for my new project(s).

Iā€™m going to check it out again and Iā€™ll also be looking at Bookends and Sente.