Scripting Scapple and allowing .scap file updates from other processes ?

Posts: 4
Joined: Thu Jun 14, 2018 7:31 am
Platform: Mac

Thu Jun 14, 2018 8:29 am Post

On macOS, if the same plain text file is open in two different applications at the same time ( like BBEdit and TaskPaper for example), changes saved to file by one app (or by a script process) are updated in the display of the other within a second or so.

Q: Is there any way of enabling this behaviour for Scapple ?


I have written some scripts which parse both .scap file XML, and any Scapple content (com.scapple.internal.pboardType) in the clipboard.

These let me:

1. Create a linked Scapple sub-file for a selected node in a scapple diagram, and
2. Save as OPML with nested indents where the Scapple content is 'acyclic' (consists of tree-like structures rather than loops)

I would, however, also like to be able to script some graphic rearrangements - for example, updating note position information in the XML file to tidy a tree diagram while it is open, and get updates on the screen without having to repeatedly go through the Save -> Dialog -> Accept sequence.


On Scapple, the default behaviour when the XML of an open .scap is changed externally (by an another app or script) is:

- No immediate update of display, and
- user choice dialog on next Save,

Screen Shot 2018-06-14 at 08.52.21.png
Screen Shot 2018-06-14 at 08.52.21.png (94.53 KiB) Viewed 2288 times

Scapple does, however, automatically update the display when a .scap file is changed by a second running instance of Scapple

(We can open the same .scap in two different instances of the Scapple app using a Bash shell line like:

Code: Select all

open -n -a Scapple "$HOME/Desktop/dag.scap"

twoScapplesOneFile.png (16.53 KiB) Viewed 2283 times

In other words:

1. Scapple CAN immediately update a display when it notices a file change,
2. But, by default, it only does so when the change is made by a process which is owned by another Scapple instance.

Is there any way of allowing it to accept file changes made by other processes, in the manner of BBEdit etc?

User avatar
Posts: 22496
Joined: Sun Jun 18, 2006 4:30 am
Platform: Mac + Linux
Location: Santiago de Compostela, Galiza

Thu Jun 14, 2018 12:01 pm Post

It looks like the main difference isn’t which program does the editing, but how the program does the editing. For example, try loading the .scap file in TextEdit and modifying the contents of a note in the XML, then save it. The change should immediately appear in the Scapple window.

Now with both windows open, edit the .scap file using Vim, Emacs or whatever you prefer on the command-line. After saving the changes there, go back to TextEdit and try to modify and save the file, you will get this dialogue box, as you will in Scapple.

In short Scapple is using the basic macOS interfaces for managing an open file. It benefits from the notification infrastructure used by other Cocoa applications (including Scapple) to keep the open instance up to date.

BBEdit, and it looks like Taskpaper as well, likely have additional code in place to handle file system changes outside of that framework. This is not an uncommon thing to do with a coding editor, and given the design intent of TaskPaper, I bet there is similar code in place as well.

While it would slow down your script a bit to do so, I wonder if committing the changes to the disk using something that works through the macOS infrastructure would improve things? I haven’t tested it, but maybe using the AppleScripting bridge could work.
Ioa Petra'ka
“Whole sight, or all the rest is desolation.” —John Fowles

Posts: 4
Joined: Thu Jun 14, 2018 7:31 am
Platform: Mac

Thu Jun 14, 2018 1:45 pm Post

Delegating the write to TextEdit works well. Thank you !