Skip to main content
Sunil Yadav
Legend
February 7, 2020
Answered

How to validate InDesign libraries using InDesign javascript?

  • February 7, 2020
  • 2 replies
  • 2624 views

Hi all,

Today I am stuck with this validation of library issue. 

How to validate a indesign library file is a valid file or not before opening it into application using javascript.

Is a way or method or something near by that.

Thing is if I take any random file instead of a proper library file and renamed it ".indl" and try to open it through javascript, entire application crashes instead of throwing error.

Instead if you open that file manually in InDesign you will get to see an error message that it is not a valid file but application never crashes.

 

Thanks

Sunil

This topic has been closed for replies.
Correct answer durai0607

Hi Sunil,

 

Please try the below code to search the Library asset name through the reading file option. I hope this will works.

Using Javascript:

 

#targetengine 'session'
var libFile = new File("/Users/user/Downloads/testlib.indl");
libFile.open('r');
var contRead = libFile.read();
libFile.close();

//[Lib]Asset Name Property - Search Words from Read String
var res = contRead.match(/\[Lib\]Asset Name Property/ig);

if(res) {
    alert("Valid library file");
} else {
    alert("Invalid library file");
}

 

 

Using Applescript:

 

tell application "Finder"
	set libFile to POSIX file "/Users/user/Downloads/testlib.indl"
	set op to open for access libFile
	set contRead to read op
	close access op
	
	--[Lib]Asset Name Property - Find Words from Read String
	if contRead contains "[Lib]Asset Name Property" then
		display alert "Valid library file"
	else
		display alert "Invalid library file"
	end if
end tell

 

 

Thanks,

Annadurai.

2 replies

Participant
October 15, 2024

Sunil singh

 

durai0607Correct answer
Inspiring
February 7, 2020

Hi Sunil,

 

Please try the below code to search the Library asset name through the reading file option. I hope this will works.

Using Javascript:

 

#targetengine 'session'
var libFile = new File("/Users/user/Downloads/testlib.indl");
libFile.open('r');
var contRead = libFile.read();
libFile.close();

//[Lib]Asset Name Property - Search Words from Read String
var res = contRead.match(/\[Lib\]Asset Name Property/ig);

if(res) {
    alert("Valid library file");
} else {
    alert("Invalid library file");
}

 

 

Using Applescript:

 

tell application "Finder"
	set libFile to POSIX file "/Users/user/Downloads/testlib.indl"
	set op to open for access libFile
	set contRead to read op
	close access op
	
	--[Lib]Asset Name Property - Find Words from Read String
	if contRead contains "[Lib]Asset Name Property" then
		display alert "Valid library file"
	else
		display alert "Invalid library file"
	end if
end tell

 

 

Thanks,

Annadurai.

Sunil Yadav
Legend
February 10, 2020

Thanks Annadurai,

This is working fine.

 

Thanks

Sunil