any way to batch update reference links???

Hi -
My wife has been using Scrivener for many years on a very large, on-going project and has made many references to things over time. She was using an old ppc Mac - which just finally quit the other day. In the needed updating process we would like to take advantage of the upset to redo her file/document structure to better reflect her current needs. But this will break all her reference links, which would be a huge problem. I have no familiarity with the software, other than that she likes it, but on a brief look at it and this knowledge base I didn’t see any way to do what we need.

We would like to go from the current link of : “localhost/Users/MyWfe/BookStuff/All My Books/Book 1/folder/folder …”
to something that would replace the path “Users/MyWife/BookStuff/All My Books/Book 1/…” to something more like
“/Users/NEW USER ID/Book 1/files to reference/”.

Is there any way to easily (i.e. not link by link manually) globally change the reference links to keep the same filename and part of the pathname of the reference, but to move the reference file to a different /User/folder structure?

Does that question make sense?

Personally, I don’t know of any way, short of, say, Applescripting, to do what you want in the way that you want to do it (although others might). If it is possible, it’s likely to involve software outside Scrivener’s scope. But… would it be feasible to recreate the old folder structure exactly where it applies to these particular files - even if some of the folders are, strictly speaking, redundant - so that the paths are identical?

Thanks - I thought that might be the case.
It certainly is possible to recreate the folder structure, and we’ll likely end up doing that - but we were hoping to reduce the redundancy, not amplify it. There’s too much redundancy as it is right now (there’s something like 8000 working files and about three times that many older ones to keep around as reference. And then backups.).

I’m not averse to applescript if it’s not too complex - I don’t want to spend a lot of time at it. (I’ve already spent way too long converting old file formats into something readable with new software - it seems that many people writing code can’t conceive of wanting to read files older than they are, even if they were written with an earlier version of the same application. Thank you Scrivener-folks for making your change to a new version process one that is simple and just works!).

I don’t see an applescript dictionary for Scrivener, so I imagine I’d have to use GUI scripting. I can generate a list of all Scrivener projects to update easily enough - do you think the user interface for the kinds of changes I’d need to make would be easily scriptable? And is there any kind of reference for finding out the things like what fieldname has content that identifies a reference link, what interface item to insert text into, or “button 3 of sheet 2 of window 1” or error messages that I might have to get into? That is, is it just pull down an accesible menu, insert some text into an easily identifiable field, and hit OK - or do I need to navigate through a whole lot of stuff, and get to the right page before I can change anything (sorry, as I said, I don’t know Scrivener’s interface)?


The file that stores this information is a plain-text file structured in simple XML. If none of that sentence put you off, then you might consider simply opening that file in a coding editor and doing a batch find & replace operation to update the path names of the links in the XML. That strikes me as easier than trying to automate the UI with a macro language. Here’s how I’d do it:

  1. With the project closed, right-click in Finder and compress a copy. This will be the backup in case things go wrong; just trash the damaged project and double-click the compressed copy to extract a fresh copy.

  2. Now right-click on the project and Show package contents.

  3. Open the .scrivx file in a plain-text editor (TextEdit’ll work in a pinch).

  4. Now you should be able to use simple search and replace to fix huge batches of changed paths at once. For reference, the lines you’re looking for are like this:

<Reference Destination="file:///Users/accountname/path/to/file.pdf">Visible description</Reference>
  1. Once done, save the .scrivx file and reopen the project in Scrivener.

Take care to properly percent-encode your replacement strings; “Book%201”, not “Book 1”.

Now if you are handy with UNIX you could probably combine some tools like find and sed to globally update all Scrivener projects simultaneously. I’ve had to do some stuff like that in the past when I’ve switched account names and such. One must be very careful with tools like that of course, but it can save a few hours or even days of manual labour.

If you would rather the macro approach, consider Scrivener’s extensive keyboard shortcut support in doing so. Here are some rough tips, as opposed to a recipe:

  • Move the active keyboard focus into the References pane with Ctrl-Opt-Cmd-N twice, then use Arrow and Tab keys to edit cells (probably need system level full keyboard access for that).
  • Testing for an end-of-list state could be done by checking for whether the Documents/Group command is active—that would indicate Tab has moved focus back to the Binder).
  • Once you’ve processed one list, Opt-Cmd-DownArrow from anywhere will select the next item in the binder sequentially.

AmberV’s suggestion of using FIND and SED (with some GREP) and directly manipulating the XML would be my first choice. Obviously not for the faint of heart though and it requires familiarity with UNIX/Linux tools and the CLI.

It’s a shame Scrivener doesn’t have direct scripting support but the Management have rightly pointed out it’s too much work for too little users who would actually use it.

I’d give you a big sloppy kiss, but it’s a bit far so,
consider it given.

Thanks so much.