Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to validate InDesign libraries using InDesign javascript?

Advocate ,
Feb 06, 2020 Feb 06, 2020

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

TOPICS
Scripting
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Feb 07, 2020 Feb 07, 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 
...
Translate
Explorer ,
Feb 07, 2020 Feb 07, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 09, 2020 Feb 09, 2020

Thanks Annadurai,

This is working fine.

 

Thanks

Sunil

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 15, 2024 Oct 15, 2024
LATEST

Sunil singh

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines