Request: commands to detach/remove/add attachment items

Users asking other users for AppleScripts that work with Bookends.
Post Reply
DrJJWMac
Posts: 345
Joined: Sat Jun 22, 2019 8:04 am
Location: Alabama USA

Request: commands to detach/remove/add attachment items

Post by DrJJWMac »

We can add and remove publication items. Please consider also including these additional commands:

* detach/remove attachment item 3 of attachment items of publication item
* add (POSIX FILE) to attachment item(s) of publication item
--
JJW
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Request: commands to detach/remove/add attachment items

Post by Jon »

That can already be done. You can access the contents of the attachment field and manipulate the attachments yourself. They are simply a newline-delimited list of file names.

attachment 1\nattachment2\nattachment\3

In your script you can remove or add attachments and then write them back to Bookends.

Jon
Sonny Software
DrJJWMac
Posts: 345
Joined: Sat Jun 22, 2019 8:04 am
Location: Alabama USA

Re: Request: commands to detach/remove/add attachment items

Post by DrJJWMac »

> You can access the contents of the attachment field and manipulate the attachments yourself. They are simply a newline-delimited list of file names.

I want to REMOVE or ADD attachment items, not manipulate the names in the attachments field.

What is the correct syntax for this operation? The important line is remove the first attachment item.

Code: Select all

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

on run {}

	set theUnfoundList to {}
	tell application "Bookends"
		activate

		-- collect the bibliographies to process
		set thePList to every publication item of front library window
	
		-- process
		repeat with thePub in thePList
			if the attachment items of thePub is not {} then
				set theAttachmentFullPath to (the path of the first attachment item of thePub) as text
				if theAttachmentFullPath is "" then
					copy the {pubname:name of the attachment item of thePub as text, pubid:id of thePub as text} to the end of theUnfoundList
					remove the first attachment item of the attachment items of thePub
				end if
			end if
		end repeat
	end tell
end run
--
JJW
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Request: commands to detach/remove/add attachment items

Post by Jon »

You don't understand. Manipulating the the names IS how you remove or add attachments.

Say you have these attachments and want to remove the second one.

file1\nfile2\nfile3\n

More easily shown as

file1
file2
file3

Get the attachments, remove the middle name, and set the attachment field to

file1\nfile3

Now that reference has only 2 attachments.

I'm no AS expert, but I googled for how to use applescript to remove a line from a list and got lots of hits

https://www.google.com/search?client=sa ... 8&oe=UTF-8

Jon
Sonny Software
DrJJWMac
Posts: 345
Joined: Sat Jun 22, 2019 8:04 am
Location: Alabama USA

Re: Request: commands to detach/remove/add attachment items

Post by DrJJWMac »

> Manipulating the the names IS how you remove or add attachments.

OK. I see now. I am able to remove or add attachments this way.

BUT ...

Once the file name is added, Bookends must search for the file to attach it. According to my test, the attachment search begins at the Attachments root folder and takes the first file. Here is how I confirmed this.

* Attachments folder --> file mytest.pdf (contains text "foo")
* Attachments/MyTest folder (default for the library) --> file mytest.pdf (contains text "bar") --> THE DESIRED FILE TO ATTACH

With the library open as the front window ...

Code: Select all

set the attachments of the publication item of the front library window to "mytest.pdf"
The attachment that is added is rooted at Attachments folder, not at the Attachments/MyTest folder as it should be.

Please correct the internal search for the attachment file to begin in the default attachments folder for the library and work backwards rather than the other way around.

This is ultimately otherwise why I wanted to add/remove the attachment item directly because I can control the path directly.
--
JJW
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Request: commands to detach/remove/add attachment items

Post by Jon »

I think we are perhaps talking at cross purposes.

Bookends itself doesn't care where the attachment is, it only cares what the name is, and that's what you're setting in that line of AppleScript. Bookends will find it it is in the default folder, a subfolder, or any ad hoc folder. Where it is located is dictated by the user.

When Bookends opens the get file dialog it uses whatever the Finder wants (which is usually the last folder accessed via a get file dialog). Once the file is found and selected you can use the subfolder popup menu in the Bookends attach dialog to direct the PDF to the library's default folder. Bookends will find it there.

Finally, as I mentioned in response to another of your requests, in the next update you will be able to get the pathname of library's default subfolder via AppleScript. I don't know if it's something you want to do, but this means you can move a file from wherever it is to that library's default folder independently of the Bookends UI.

Jon
Sonny Software
DrJJWMac
Posts: 345
Joined: Sat Jun 22, 2019 8:04 am
Location: Alabama USA

Re: Request: commands to detach/remove/add attachment items

Post by DrJJWMac »

> I think we are perhaps talking at cross purposes.

I hope not cross purposes, rather different needs.

> Bookends itself doesn't care where the attachment is, it only cares what the name is, and that's what you're setting in that line of AppleScript. Bookends will find it it is in the default folder, a subfolder, or any ad hoc folder. Where it is located is dictated by the user.

A user and the Finder know that these two files are different.

Attachments/mytest.pdf
Attachments/Library1/mytest.pdf

Bookends enforces that, as attachments, they are the same and one of them must be renamed.

Sidebar: The strongest feature of Bookends among all other bibliography management apps is its ability to split libraries into smaller pieces. But, Bookends defeats itself in exploiting the full power of this feature when it can only recognize differences in files by their name, not by their unique location. It is the same problem as a traveler believing that Rome, GA USA is the same as Rome, Italy ... and insisting that we will have to rename one or the other cities. Alternatively, view Bookends as a database management app for attachments. No other database app that I know forces me to have to consider that my attachments have to be renamed if they are COPIES in different folders at the Finder level. I have by example about a half dozen files called che342hmwrk01.pdf in my DevonThink database because, over the years, I've (mis)managed to copy that one assignment to different Finder locations.

I have the ability to do this duplicate management at the Finder level. But in Bookends, I do not have this ability. At all.

> but this means you can move a file from wherever it is to that library's default folder independently of the Bookends UI.

This option is entirely workable for MOVING. It is entirely unworkable for COPYING. I am focused on COPYING. For me, data storage is cheap. So, I make a duplicate of the attachment into a new library. It keeps the database entirely self-contained.

Now that I understand the limitation, I have in mind to add a prefix to my COPIED file names in order for Bookends to distinguish the differences in file names. In essence, you would then have this ...

Attachments/mytest.pdf
Attachments/Library1/Library1_mytest.pdf

The two files are identical. They are just named differently. I really should not have to do this.

In the meantime, my overriding request is that Bookends be fixed to respect the default library folder for a library as the FIRST location to a) put any new attachment from any operation (drag + drop, attach, or sync) and b) search for any newly attached file name (e.g. after an AppleScript run changes the attachments name field). At the moment, all of the operations appear to start always at the root Attachments folder. By example, syncing a library from Bookends iOS puts new attachments at the root Attachments folder rather than in the default attachments folder for the library.
--
JJW
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Request: commands to detach/remove/add attachment items

Post by Jon »

Yes, I mentioned that earlier. When you copy add some distinguishing text to the name (Bookends adds a random number), which solves this problem.

The fact that Bookends uses the unique file name, and not the pathname, to identify attachments is a major advantage, which you ignore. It gives you enormous flexibility. You can store PDFs anywhere you want, not in a predefined location (although you can do that, too). You can move the attachments to a new Mac and Bookends will find your PDFs automatically (in the worst case when using ad hoc folders you'll need to reattach one PDF from that folder and then all PDFs will be found). And so on. Bookends creates the unique name for you, so for 99.9% of users this is totally transparent. If you're scripting Bookends then it's not a big deal to do the same. It's a feature, not a bug, and it's not going to change.

If you have a request about syncing to iOS please start a new thread in the Bookends for iOS forum.

Jon
Sonny Software
DrJJWMac
Posts: 345
Joined: Sat Jun 22, 2019 8:04 am
Location: Alabama USA

Re: Request: commands to detach/remove/add attachment items

Post by DrJJWMac »

> The fact that Bookends uses the unique file name, and not the pathname, to identify attachments is a major advantage, which you ignore.

I understand the advantage. By comparison though, when I move my DevonThink database or Curio project to a new computer, all the file links also still work. So, somehow, what you are achieving in Bookends by using unique names is achievable elsewhere without such an approach.

> It's a feature, not a bug, and it's not going to change.

I will work with/around it accordingly.

> If you have a request about syncing to iOS please start a new thread in the Bookends for iOS forum.

I believe I had sent a support request by email. I will post to the iOS forum as well for records.
--
JJW
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Request: commands to detach/remove/add attachment items

Post by Jon »

I don't know about Curio, but DTP seems to make a copy of the PDF and store it in the database bundle

https://discourse.devontechnologies.com ... nk/55861/3

I added a PDF attachment in DTP and at least in my case I found this to be true -- a copy was stored in the database bundle.

Building a closed garden certainly works, but it, too, has obvious limitations and compromises. We chose another route, one I greatly prefer, but of course one with which you disagree.

Jon
Sonny Software
Post Reply