Site logo

Examples of running AppleScript from JavaScript

function CreateAliasesSetLabels(theIssueFolderName) {
	if (File.fs == "Macintosh") {
		var appleScript = 'tell application \"Finder\"\r';
		appleScript += 'set theMainFolder to a reference to folder "L\'Express:"\r';
		appleScript += 'set theIssueFolderName to "' + theIssueFolderName+ '"\r';
		appleScript += 'set theIssueFolderPath to "L\'Express:Archives L\'Express:" & theIssueFolderName & ":" as string\r';
		appleScript += 'set theIssueFolder to a reference to folder theIssueFolderPath\r';
		appleScript += 'set theAnnouncesFolderPath to "L\'Express:Archives L\'Express:" & theIssueFolderName & ":~ ANNOUNCES" as string\r';
		appleScript += 'set theAnnouncesFolder to a reference to folder theAnnouncesFolderPath\r';
		appleScript += 'set theAlias1 to make new alias to theIssueFolder at theMainFolder with properties {name:"~ Cette Semaine PAGES"}\r';
		appleScript += 'set label index of theAlias1 to 6\r';
		appleScript += 'set theAlias2 to make new alias to theAnnouncesFolder at theMainFolder with properties {name:"~ Cette Semaine ANNOUNCES"}\r';
		appleScript += 'set label index of theAlias2 to 3\r';
		appleScript += 'set theBookPath to theIssueFolderPath & theIssueFolderName & ".indb:"\r';
		appleScript += 'set theBook to a reference to file theBookPath\r';
		appleScript += 'set label index of theBook to 6\r';
		appleScript += 'end tell';
		
		$.writeln(appleScript);
		
		try {
			app.doScript(appleScript, ScriptLanguage.applescriptLanguage);
		}
		catch(err) {
			$.writeln(err.message + ", line: " + err.line);
		}
	}
}

 

 

See also doScript() method

Go back to the main InDesign code samples page