Accessing library items from scripts
Copy link to clipboard
Copied
Hello,
Is it possible to access library items from scripts?
Really hope there is a way!
Many thanks
Smyth
Copy link to clipboard
Copied
CC libraries no, local libraries yes through Extendscript.
Copy link to clipboard
Copied
Hello,
Thank you for your reply, so in theory a library which sits on my desktop I could access via a script?
My thinking is, if you can access libary items, would there be a way to make a script to do things to particular library items via the name of those items?
For example if you really wanted to, can you do a paste in place via the script looking for say library item called 'template'... this is just
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Library.html
Best,
Smyth.
Copy link to clipboard
Copied
Hi @SmythWharf
By “library item” do you mean the library itself or some particular asset within such a library? I guess you're using the latter sense (?)
- As such, the Library object (container of assets) corresponds to an indl file — assuming local lib — and can be accessed and/or instanciated through app.libraries. This collection is empty if no library is presently available (=opened) in InDesign, but you can use app.libraries.add("/path/to/MyLibrary.indl"); to load a particular library. The name property of a Library instance — still assumed local — is the underlying file name. If your library is already loaded in ID, just use myLib = app.libraries.itemByName("MyLibrary.indl"); to get the corresponding specifier.
- From then, go to the Assets collection (myLib.assets) to navigate through the items this library contains. As usual, those elements are accessible by index or by name. So, if a particular asset is named template, you can easily retrieve a specifier using myAsset = myLib.assets.itemByName("template"); and then enjoy the Asset API. What you're probably looking after is myAsset.placeAsset(<where>), whose <where> argument refers to either a Document or Text instance, and which returns the placed item(s) as an array. The placeAsset behavior/target depends on myAsset.assetType, but in common cases you should expect this method to position the placed asset at its original location, that is, at the coordinates it owned when the InDesign user drag&dropped the item into the Library panel. (Changing the default placeAsset mechanism is an open question to me, although I admit I haven't experimented much in this field.)
Best,
Marc
Copy link to clipboard
Copied
Hello,
This is excellent starter information. Very curious indeed.
Best,
Smyth

