Skip to main content
Adirai Maji
Inspiring
January 21, 2020
Answered

How can I check whether if "Allow Scripts to Write Files and Access Network" is enable using Script?

  • January 21, 2020
  • 3 replies
  • 2941 views

I want to check if Allow Scripts to Write Files and Access Network eneabled via scripting. It is doable, I've seen some scripts do that check before run some functions. How can I check that radio button inside preferences settings???

This topic has been closed for replies.
Correct answer Tomas Sinkunas

Here's a barebone function that will check if Allow Scripts to Write Files and Access Network is enabled or disabled

function canWriteFiles() {
	var appVersion, commandID, scriptName, tabName;

	appVersion = parseFloat(app.version);

	commandID = 2359;
	tabName = 'General';
	if (appVersion >= 16.1) {
		commandID = 3131;
		tabName = 'Scripting & Expressions';
	}

	if (isSecurityPrefSet()) return true;

	scriptName = (script && script.name) ? script.name : 'Script';
	alert(message = scriptName + ' requires access to write files.\n' +
		'Go to the "' + tabName + '" panel of the application preferences and make sure ' +
		'"Allow Scripts to Write Files and Access Network" is checked.');

	app.executeCommand(commandID);

	return isSecurityPrefSet();

	function isSecurityPrefSet() {
		return app.preferences.getPrefAsLong(
			'Main Pref Section',
			'Pref_SCRIPTING_FILE_NETWORK_SECURITY'
		) === 1;
	}
}

 

3 replies

Tomas Sinkunas
Tomas SinkunasCorrect answer
Legend
January 22, 2020

Here's a barebone function that will check if Allow Scripts to Write Files and Access Network is enabled or disabled

function canWriteFiles() {
	var appVersion, commandID, scriptName, tabName;

	appVersion = parseFloat(app.version);

	commandID = 2359;
	tabName = 'General';
	if (appVersion >= 16.1) {
		commandID = 3131;
		tabName = 'Scripting & Expressions';
	}

	if (isSecurityPrefSet()) return true;

	scriptName = (script && script.name) ? script.name : 'Script';
	alert(message = scriptName + ' requires access to write files.\n' +
		'Go to the "' + tabName + '" panel of the application preferences and make sure ' +
		'"Allow Scripts to Write Files and Access Network" is checked.');

	app.executeCommand(commandID);

	return isSecurityPrefSet();

	function isSecurityPrefSet() {
		return app.preferences.getPrefAsLong(
			'Main Pref Section',
			'Pref_SCRIPTING_FILE_NETWORK_SECURITY'
		) === 1;
	}
}

 

Adirai Maji
Inspiring
January 23, 2020

Thank you so much.

Mylenium
Legend
January 21, 2020

Well, you have access to the prefs file via the respective functions. Otherwise any function that is dependent on network access like opening a socket connection will simply trigger a warning. Nothing particulalrly smart about it required.

 

Mylenium

Community Expert
January 21, 2020

You will find the option in the Preferences>Scripting and Expressions panel:

In previous versions of AE the option is in the Preferences>General Panel just below the middle.

Adirai Maji
Inspiring
January 21, 2020

I'm asking about scripting. How can I check if it enabled or not using extendScript??

Community Expert
January 21, 2020

As far as I know, there is no connection between scripts and preferences. The user will just get an error.