any way to batch update reference links???

pe
peterz
Posts: 3
Joined: Sun Apr 16, 2017 1:45 am
Platform: Mac

Wed Apr 19, 2017 4:00 pm Post

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?
Thanks
Peter

Hu
Hugh
Posts: 2444
Joined: Thu Mar 08, 2007 12:05 pm
Platform: Mac
Location: UK

Wed Apr 19, 2017 5:13 pm Post

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?
'Listen, some quiet night, when you've shirked your work that day. Do you hear
that distant, almost inaudible clicking sound? That's one of your
competitors, working away in the night in
Paris or London or Erie, PA.'

pe
peterz
Posts: 3
Joined: Sun Apr 16, 2017 1:45 am
Platform: Mac

Wed Apr 19, 2017 7:43 pm Post

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)?

Peter

User avatar
AmberV
Posts: 23483
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Ourense, Galiza
Contact:

Wed Apr 19, 2017 9:08 pm Post

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:

    Code: Select all

    <Reference Destination="file:///Users/accountname/path/to/file.pdf">Visible description</Reference>

  5. 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.
.:.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

User avatar
ChrisRosser
Posts: 242
Joined: Tue Jun 26, 2007 12:11 pm
Platform: Mac + iOS
Location: Melbourne, AU
Contact:

Wed Apr 19, 2017 11:15 pm Post

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.
Mild-mannered Technical Writer by day, closet fantasist by night
I run Scrivener on macOS and iOS :mrgreen:

Website | Scrivener Articles
Amazon | Twitter | Facebook

pe
peterz
Posts: 3
Joined: Sun Apr 16, 2017 1:45 am
Platform: Mac

Thu Apr 20, 2017 3:58 pm Post

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

Thanks so much.

pa'gozar
Peter