Hello,
I’m hoping someone can help me figure out how to script adding an item to an InDesign library. The bolded and italicized line is my guess that didn’t work.
tell application “Adobe InDesign CS6”
set lib_list to get name of libraries
set test_lib to item 1 of lib_list
log test_lib
set the_sel to the selection
log the_sel
add item the_sel to library test_lib with properties {name:“Black square”}
end tell
I figured it out! Here’s the full code so far. The solution is towards the bottom of the script in case anyone else is looking for the same thing.
--------------------------------------------------------------------------------------
--SPECIFYING THE FOLDER WHERE LIBRARY FILES ARE STORED
--------------------------------------------------------------------------------------
--Setting the path to the folder where library files are stored
--Replace with the path where you saved the library files
set library_path to path to desktop as string
--------------------------------------------------------------------------------------
--GETTING CURRENT LIBRARIES
--------------------------------------------------------------------------------------
tell application "Adobe InDesign CC 2018"
--Getting a list of every library
set the_libraries to libraries
--------------------------------------------------------------------------------------
--FIGURING OUT THE ASSET NAME
--------------------------------------------------------------------------------------
--Getting the name of images in the file
tell active document
set used_name to ""
set the_images to all graphics
repeat with an_image in the_images
set the_link to item link of an_image
set image_name to name of the_link
set image_path to file path of the_link
if image_path contains "4c IMAGES" then
set used_name to image_name
set used_path to image_path
end if
end repeat
end tell
--Removing _s_4c, . and extension from name
if used_name is not "" then
tell application "Finder" to set name_ext to name extension of (used_path as alias)
if used_name contains ("_s_4c." & name_ext as string) then
set dot_ext to "_s_4c." & name_ext as string
else
set dot_ext to "." & name_ext as string
end if
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to dot_ext
set asset_name to first text item of used_name
set AppleScript's text item delimiters to tid
end if
--------------------------------------------------------------------------------------
--FIGURING OUT WHICH LIBRARY THE ASSET SHOULD GO INTO
--------------------------------------------------------------------------------------
--Determining what department library the asset should be added to
--This is based off the prefix in the image name
if (text 1 thru 2 of asset_name as string) contains "AU" then
set library_name to "Automotive_Products"
else if (text 1 thru 2 of asset_name as string) contains "PA" then
set library_name to "Paint_Products"
else if (text 1 thru 2 of asset_name as string) contains "PT" then
set library_name to "Tools_Products"
else if (text 1 thru 2 of asset_name as string) contains "PL" then
set library_name to "Plumbing_Products"
else if (text 1 thru 2 of asset_name as string) contains "TR" then
set library_name to "Automotive_Products"
end if
--------------------------------------------------------------------------------------
--OPENING THE LIBRARY
--------------------------------------------------------------------------------------
--Opening the library
set full_library_name to library_name & ".indl" as string
set theLib to open (library_path & full_library_name)
--------------------------------------------------------------------------------------
--ADDING THE ASSET TO THE LIBRARY
--------------------------------------------------------------------------------------
--Selects all groups if nothing is selected
--This is what I want it to do, you may wish to take this part out
if selection is {} then
tell active document to set the_groups to every group
set group_count to count the_groups
if group_count is 1 then
select all
end if
end if
--Storing the asset in the library
if selection is not {} then
set assetRef to selection
tell theLib
--The magical line of code I was looking for
set assetRef to store using assetRef with properties {name:asset_name, description:"Just a test", asset type:geometry type}
end tell
end if
end tell