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

Don’t lose heart. The ability to create entries at the bottom of the binder with defined terms for title and contents (optionally, abstract) would be a great first step - metadata options can wait, and import is probably more important to most people than export, so you could also just put export off until later.

I don’t know enough about the inner workings of Scrivener to understand how you would support non-textual importing, but I’m assuming you would use a create/import which accepts either a POSIX path or URL in order to import images, pdfs, webarchives, weblocs etc.

My extremely unscientific guess is that creating title/contents and importing POSIX paths or URLs is 90% of your use cases - some people (like me) will also be extremely excited about preserving particular metadata (mailtags-keywords, file datestamps, labels etc.) or about exporting, but that is probably your last 10%, and can wait.

I’m not entirely clear on what an application has to include in its suite as opposed to things (if any) that are just part of OS X, but here are a few thoughts:

selected text
selected binder document
convert (binder document into folder)
insert (as in inserting a file on your computer into the Binder)
create (create a new blank document in the Binder)
merge (merge two documents in the Binder)
split (split a document into two at the insertion point)
move to trash
empty trash

Also have a window class (id, position, bounds, etc).

Just noticed this thread, and yes I have some ideas :slight_smile:

To get a general feel what an Applescript Suite should support, run the Script Editor and open the dictionary for DevonThink. You’ll notice two types of exports: data types (i.e. objects with properties) and actions (routines called to get objects or interact with the app).

If I were adding Applescript for Scrivener, I’d add at least the following data types:

Application (has Active Wndow contains DocumentWindow, Current Project, Recent Projects, etc)
DocumentWindow (has Selected Text and such)
Project (has name, notes, contains Binder)
Binder (contains BinderItems, has Root Group which contains Drafts/Trash/etc)
BinderItem (has name, path, synopsis, notes, references, type, label, status, keywords, etc)

…and so forth.

I’d support the following actions like the following:

open project (closes current project)
create binder item at path
delete (to trash) binder item at path
move binder item at path to path
get binder item at path
take snapshot
backup project to file_path
export project to file_path
import file at file_path to path

Applescript is used for two things: automation and interacting with other applications (could be considered the same thing actually).

This means that there needs to be direct access to the raw data in Scrivener (text, keywords, labels, status, references, and notes) via data types, and access to commonly-automated tasks (opening, saving, exporting, importing) via actions.

In an application like Scrivener, exposing the data types (which are all native to OS X and will play well with Applescript) is more important that providing routines. Consider the likely use cases, and how the scripts for them would be written:

  • List unfinished items: iterate over documents, printing all with TODO status. Same applies for listing document keywords, references, etc.
  • Add metadata to a document: find document, modify notes/ref/keyword/status/synopsis
  • Apply text changes: find document, modify RTF directly
  • Add file to project: invoke import routine
  • Export data from project: compile export settings and list of object IDs to export, then invoke export routine
  • Send selected text to application : get selected text, tell application

I don’t see much value in adding applescript support for the kind of stuff that generally requires human interaction/judgement, e.g. merging and splitting documents/empty trash, or for the stuff that applescripts can easily do themselves, e.g. convert case/insert date/etc.

So the heart of the applescript suite would be the BinderItem data type:

BinderItem
Name (string)
Location (string: path from Binder root)
Path (string: path inside project dir)
Type (r/o)
Title (string)
Label (integer)
Status (integer)
Synopsis (string)
Create Date (r/o)
Mod Date (r/o)
Include in Export (boolean)
Page Break Before (boolean)
Preserve Formatting (boolean)
Notes (string)
Keywords (list of Keyword objects)
References (list of Reference objects)
Target (?)
Progress (?)
Children (list of BinderItem objects)

Note word count and char count are unneccessary for BinderItem as they are inherent properties of applescript strings, though per-project counts should be included.

Based on this, the rest of the data types become obvious (Reference, Keyword, Binder containing BinderItems, Window containing Binder, Application containing Window), and the routines simply become ways to either to access (create/find/delete) the types, or to perform operations that aren’t related to modifying data stored in types.

Thanks edf - they are great ideas and that looks like a very good start for an AppleScript suite. Shame that implementing the Cocoa side of it looks a lot more difficult (and obliquely documented) than I had hoped…

You mean it’s not as simple as setting NSAppleScriptEnabled to True in the plist? :wink:

Yeah, scoping out the Cocoa Scripting Guide doc, it looks a bit involved, and the writing is rather obtuse. Reads like agile programming books.

This guy has a decent (but possibly outdated) play-by-play of adding applescript to an app, if it helps:

http://www.stone.com/The_Cocoa_Files/Adding_Applescript.html

Some complaints and workarounds are given here:

http://earthlingsoft.net/ssp/blog/2004/07/cocoa_and_applescript

All this Cocoa discussion makes me glad I’m off doing backend stuff these days.

Good luck! I’m looking forward to scripting Scrivener

I’m not an AppleScripter, either. Like a lot of “serious” software developers I’m put off by the language syntax. But I think it’s worth learning it, and if you add AppleScript support to Scrivener that’s even more reason for me to learn AppleScript.

I would mainly use it to automate export (especially in Markdown format). I write my short stories in Scrivener and it would be great to have a script to automatically publish them to me website. For this I would need to AppleScript access to the whole export process.

Apart from that, access to all binder elements would be great, too, especially, to be able to create new folders and chapters.

BTW, if you don’t like the AppleScript syntax have a look at AppScript. It provides access to AppleScript suites in Python, Ruby and even Objective-C: appscript.sourceforge.net/

Jürgen

Applescript truly is a horrible language – it’s been called the only read-only programming language (in the sense that Perl is a write-only language). The core concepts, though – the ‘tell’ blocks that send messages to receivers defined in applications or linked-in standard libraries – work great as glue in a GUI environment. Quite possibly the best GUI analogue to UNIX shell pipes.

Appscript is a nice improvement, with one fatal flaw: it doesn’t ship with OS X (well two flaws: the versions of python and ruby that ship with OS X are ancient enough to be all but useless). If you plan to distribute your scripts, even just to less-technical friends, you will face install issues.

Personally, I’ve gotten a lot of mileage out of osascript and ‘do shell script’, though I’m sure I reimplement a fair portion of appscript in the process :slight_smile:

First of all, the versions of Python and Ruby are not that ancient (well, that depends on how you define “ancient”). They were the state of the art when Tiger was released more then a year ago. I think the Ruby version shipping with Tiger is 1.8.2, and the most current is 1.8.6.

Apple is very open to integrating open source components. Leopard will ship with RubyCocoa, for example, fully integrated in XCode (and also with Rails, btw). So I don’t see that we won’t see AppScript integrated, perhaps even as soon as with the release of Leopard.

Jürgen

Thanks all for feedback. AppleScript is now unlikely to make it into anything like 1.1 and probably will, after all, be held back until 1.5 or 2.0. Further investigation has revealed just how much work this would be - too much for the time being, unfortunately. Still, I will keep this thread open and use it for reference when the time comes.

Oh, and you are all banned from mentioning Leopard. Apple’s refusal to make the WWDC beta available to paying ADC members (despite the fact that pirates can already download it as a torrent) makes me so mad that I can’t actually name the spotted cat without spitting venom. :imp:

Best,
Keith

Now, I just don’t get that. Assuming, as I do, that just about every corporation out there is bent on one thing and one thing only - making money - this whole thing still just doesn’t make sense. Withholding that beta from developers isn’t going to make Appleany money, not that I can see, and it wouldn’t hurt them at all to make it available. I’m just not seeing the reasoning behind the whole thing. If there’s no benefit to them, why is it happening? Doing such a thing on purpose will only make people mad. Is there more to this that I’m not understanding here?

/me injects precautionary anti-venom

Here is my outsider, unsubstantiated, unfounded, and completely clueless guess: They rushed a beta distribution out for WWDC attendees which may or may not be stable enough to push out to all ADC members. They are probably collecting initial bug reports from the recipients right now, but are unable to fully act on them because–as we all know–the L*@pard team is gutted and on the iPhone project which goes mainstream in a little over a week. Firmware work can be done up until a much later date than fabrication work, so I wouldn’t doubt they are pushing long hours on that project.

So once again, I curse the iPhone as the bane of Leo&ar!.

I’m afraid for once, AmberV, your reasoning doesn’t hold. You forget that those of us who have paid for ADC membership are already running older, less stable Leopard seeds. I’m running a seed from two months ago to develop Scrivener (it has to be linked using the latest version of Xcode to run on both Leopard and Tiger) and Xcode crashes on me regularly.

And I’ve already moaned elsewhere how the Leopard Early Start Kit page actually advertises access to the “latest” versions of Leopard, so really, there is even a case for dodgy advertising here, too. Nope, I am really, really angry about this. It is Apple at their worst.

Best,
Keith

It’s been a while since anyone posted to this topic - I suppose you’ve got the latest Leopard seed by now though (I hope!)

My question is when will Scrivener be available for Leopard, given it smells like the cat is close?

My trial expired just as a few other more immediate expenses piled up, but I do plan to buy in about a month (I really miss the program!) so I’m wondering about your Leopard timing? Any comments you can make?

Oh, and in the meantime (after you put up your Leopard version but before I can afford it!), will you be updating your site with nice-looking screenshots, so I can know what I’m missing out on? :slight_smile:))

Hi,

The beta in the Beta Testing forum is Leopard-ready. The 1.09 beta will be out in a day or two, then 1.1 will be released officially before Leopard hits the shelves (unless Apple just drops it on the shelves without announcing it). The site will be updated with new screenshots at the same time as 1.1 comes out.

And by the way, the 1.08 beta in the Beta Testing forum restarts the trial and gives you 30 days of actual use, so you can continue using the program for a while longer if you download it. :slight_smile:

All the best,
Keith

Thanks, I downloaded it and it looks great!

It’s even better than I remember from a few weeks ago.

Definitely on my “buy” list.

I just got my first Mac, and saw the plug for Scrivener on Slashdot, so I gave it a try. It looks GREAT. The first thing I thought after running through the tutorial is how this would help in writing blog posts. The research and link collection features would be helpful, and if the posts are all collected in Scrivener, it would make selecting certain ones and merging them into a book (someday) really easy as well.

I’m not familiar with Apple script (yet), but I’m guessing the uploading could be automated if there is script access to the files in the binder and the file metadata, especially status, so the script could know what articles and associated files (images, etc) need to go up. The ability to add arbitrary custom metadata fields would be very helpful to this as well. I think this feature would be inappropriate for the main program, but very doable with AS/Cocoa given the right interface exposure.

AUTOMATOR SUPPORT
developer.apple.com/macosx/automatormarket.html

developer.apple.com/documentatio … mator.html

macdevcenter.com/pub/a/mac/2 … mator.html

spiderworks.com/books/automator.php

Am I the only one who doesn’t know what AppleScript or Automator are for?

Nope. I say that as someone who does know, but who has provided others a longwinded and meandering answer several times lately. It all boils down to providing you the ability to extend, automate, or combine various components of your system. When you need to use either, they will suddenly start making sense.

At least I think it all boils down to that.

I’d love to see robust Applescript support. Of the mac word processors I think Pages has the best Applescript support – I’d look at the Pages dictionary for an idea of the possibilities.

To give an example of its advantages – Jim Harrison has been able to write a BibDesk (BibTex-focused bibliography manager) for Pages using Applescript – jhh.med.virginia.edu/main/CiteInPages. I thought about doing the same thing for Nisus Writer Pro & realized that NWP’s Applescript support is pretty limited, with not much more than TextEdit and developers who are focusing on a proprietary Perl-based macro language instead of Applescript (don’t get me started on that…).