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

How to validate InDesign libraries using InDesign javascript?

Advocate ,
Feb 06, 2020 Feb 06, 2020

Copy link to clipboard

Copied

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

Views

2.4K

Translate

Translate

Report

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 
...

Votes

Translate

Translate
Explorer ,
Feb 07, 2020 Feb 07, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thanks Annadurai,

This is working fine.

 

Thanks

Sunil

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Sunil singh

 

Votes

Translate

Translate

Report

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