Get every publication item from a smart group

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

Get every publication item from a smart group

Post by chittu »

I am trying to export the formatted references to a text file. I am using a keyword (called "read_it") to filter the entire library and saving the result into a text file. My question is, can I export a smart group (called "group_read_it") that already has the filtered reference using the keyword ("read_it")? searching a keyword in the entire library takes time and slows down the entire process!

I am not sure if one can export the references from a smart filter although few groups like "group recently viewed" does work well, here is my AppleScript that works well to filter the entire library with keyword search

Code: Select all

tell application "Bookends"
	tell front library window
		set myPubs to every publication item whose keywords contains "read_it"
		if myPubs is not {} then
			set theBody to format myPubs using "read_it" as HTML
		end if
	end tell
end tell
set outputFile to ((path to desktop as text) & "LaunchAgent_Alert.html") -- represents "MacHD:Users:chittu:Desktop:LaunchAgent_Alert.txt"
try
	set fileReference to open for access file outputFile with write permission
	write theBody to fileReference
	close access fileReference
on error
	try
		close access file outputFile
	end try
end try
lucius
Posts: 4
Joined: Tue Dec 03, 2019 11:19 am

Re: Get every publication item from a smart group

Post by lucius »

Try this:

Code: Select all

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

tell application "Bookends"
	tell front library window
		set GroupsList to every group item's name
		set the_selection to choose from list GroupsList
		if the_selection is false then
			error number -128 -- User canceled 
		else
			set groupName to item 1 of the_selection
			set myPubs to publication items of group item groupName
		end if
		if myPubs is not {} then
			set theBody to format myPubs using "read_it" as HTML
		end if
		
	end tell
end tell

set outputFile to ((path to desktop as text) & "LaunchAgent_Alert.html") -- represents "MacHD:Users:chittu:Desktop:LaunchAgent_Alert.txt"
try
	set fileReference to open for access file outputFile with write permission
	write theBody to fileReference
	close access fileReference
on error
	try
		close access file outputFile
	end try
end try
chittu
Posts: 25
Joined: Wed Mar 25, 2015 9:36 am

Re: Get every publication item from a smart group

Post by chittu »

excellent! this works well. Is it possible to include the name of the smart group (namely "read_it") in the script? current script requires the user's input (choose from the list). I did try myself but I can't get it working.
lucius
Posts: 4
Joined: Tue Dec 03, 2019 11:19 am

Re: Get every publication item from a smart group

Post by lucius »

What do you mean ?
Instead of the full list of groups ?

Here you go:

Code: Select all

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Bookends"
	tell front library window
		set GroupName to "read_it"
		set myPubs to publication items of group item GroupName
		if myPubs is not {} then
			set theBody to format myPubs using "read_it" as HTML
		end if
	end tell
end tell

set outputFile to ((path to desktop as text) & "LaunchAgent_Alert.html") -- represents "MacHD:Users:chittu:Desktop:LaunchAgent_Alert.txt"
try
	set fileReference to open for access file outputFile with write permission
	write theBody to fileReference
	close access fileReference
on error
	try
		close access file outputFile
	end try
end try
chittu
Posts: 25
Joined: Wed Mar 25, 2015 9:36 am

Re: Get every publication item from a smart group

Post by chittu »

thanks it works, earlier, I missed to add double quote around the group name (read_it), so it gave me an error.
Post Reply