Get full path of the attachment (selected item)

Users asking other users for AppleScripts that work with Bookends.
Post Reply
chittu
Posts: 23
Joined: Wed Mar 25, 2015 9:36 am

Get full path of the attachment (selected item)

Post by chittu »

Can you help me to get an apple script that can get me the absolute path of the attachment of a selected reference? At the moment (without AppleScript), I have a format in Bookends that includes full path and I manually copy the full path, although it works it is a tedious process (I have to choose the format first, select the formatted text, copy it and past it to terminal (for file transfer)

msteffens
Posts: 33
Joined: Thu Jul 19, 2007 10:04 am
Location: Germany
Contact:

Re: Get full path of the attachment (selected item)

Post by msteffens »

chittu wrote:
Sat Dec 28, 2019 10:25 am
Can you help me to get an apple script that can get me the absolute path of the attachment of a selected reference?
Using Bookends 13.2.1 or greater, the below AppleScript code should work:

Code: Select all

-- Returns the absolute path of the first attachment of the first publication
-- selected in the front Bookends window.
tell application "Bookends"
	tell front library window
		set selectedPubs to selected publication items
		if selectedPubs is not {} then
			set aPub to first item of selectedPubs
			set filePath to my firstAttachmentPathFromPublication(aPub)
			get filePath
		end if
	end tell
end tell

-- For the given Bookends publication, returns the absolute path of its
-- first attachment (if there's any), otherwise returns an empty string.
on firstAttachmentPathFromPublication(aPublication)
	if aPublication is missing value then return ""
	
	tell application "Bookends"
		set pubFiles to attachment items of aPublication
		if pubFiles is {} then return ""
		
		set aFile to first item of pubFiles
		set filePath to path of aFile
		return filePath
	end tell
end firstAttachmentPathFromPublication
You could, of course, also get the paths of all attachments for a certain publication, or get all paths of all selected publications.

Post Reply