How to change CameraRaw settings in Photoshop CS 6 settings with ExtendScript?

Participant ,
Dec 29, 2020

Copy link to clipboard

Copied

Hello,

 

In my Photoshop CS 6 (Mac) settings, CameraRaw is set to only open RAW images, but sometimes I have to open JPG images in CameraRaw. This can be done manually by modifying a specific setting: Photoshop Settings -> Files -> CameraRaw Settings -> Files Settings

(I don't know the labels in english as I have a french localized Photoshop version)

 

Is there a way with ExtendScript to change this specific setting? I would like a script to easily switch between "Use CameraRaw to open JPG files with parameters / Always use CameraRaw to open JPG files".

 

Thank you.

 

psd.jpg

Adobe Community Professional
Correct answer by Stephen_A_Marsh | Adobe Community Professional

On the Mac, one can set the standard open options to force a supported TIFF or JPEG to open into ACR:

 

force-acr.png

 

Another approach would be to force the JPEG/TIFF to open via:

 

 

OpenDocumentType.CAMERARAW

 

 

Obviously more code is required than just that snippet, however, I couldn't get that to work, but I hacked at the following script and it did work:

 

 

//community.adobe.com/t5/photoshop/how-to-record-button-click-on-action/td-p/10858184
var forceACR = File.openDialog("Please select a JPEG or TIFF file");
var d = new ActionDescriptor();
d.putBoolean(stringIDToTypeID("dontRecord"), true);
d.putBoolean(stringIDToTypeID("forceNotify"), true);
d.putPath(stringIDToTypeID("null"), forceACR);
var d1 = new ActionDescriptor();
d.putObject(stringIDToTypeID("as"), stringIDToTypeID("Adobe Camera Raw"), d1);
d.putBoolean(stringIDToTypeID("smartObject"), true);
d.putBoolean(stringIDToTypeID("overrideOpen"), true);
executeAction(stringIDToTypeID("open"), d, DialogModes.ALL);

 

 

TOPICS
Actions and scripting

Views

137

Likes

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

How to change CameraRaw settings in Photoshop CS 6 settings with ExtendScript?

Participant ,
Dec 29, 2020

Copy link to clipboard

Copied

Hello,

 

In my Photoshop CS 6 (Mac) settings, CameraRaw is set to only open RAW images, but sometimes I have to open JPG images in CameraRaw. This can be done manually by modifying a specific setting: Photoshop Settings -> Files -> CameraRaw Settings -> Files Settings

(I don't know the labels in english as I have a french localized Photoshop version)

 

Is there a way with ExtendScript to change this specific setting? I would like a script to easily switch between "Use CameraRaw to open JPG files with parameters / Always use CameraRaw to open JPG files".

 

Thank you.

 

psd.jpg

Adobe Community Professional
Correct answer by Stephen_A_Marsh | Adobe Community Professional

On the Mac, one can set the standard open options to force a supported TIFF or JPEG to open into ACR:

 

force-acr.png

 

Another approach would be to force the JPEG/TIFF to open via:

 

 

OpenDocumentType.CAMERARAW

 

 

Obviously more code is required than just that snippet, however, I couldn't get that to work, but I hacked at the following script and it did work:

 

 

//community.adobe.com/t5/photoshop/how-to-record-button-click-on-action/td-p/10858184
var forceACR = File.openDialog("Please select a JPEG or TIFF file");
var d = new ActionDescriptor();
d.putBoolean(stringIDToTypeID("dontRecord"), true);
d.putBoolean(stringIDToTypeID("forceNotify"), true);
d.putPath(stringIDToTypeID("null"), forceACR);
var d1 = new ActionDescriptor();
d.putObject(stringIDToTypeID("as"), stringIDToTypeID("Adobe Camera Raw"), d1);
d.putBoolean(stringIDToTypeID("smartObject"), true);
d.putBoolean(stringIDToTypeID("overrideOpen"), true);
executeAction(stringIDToTypeID("open"), d, DialogModes.ALL);

 

 

TOPICS
Actions and scripting

Views

138

Likes

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
Dec 29, 2020 0
LEGEND ,
Dec 29, 2020

Copy link to clipboard

Copied

I don’t have CS6 installed anymore (as it would not run on my OS) so I cannot test this, but have you tried recording the changing of the setting with ScriptingListener.plugin? 

Likes

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
Reply
Loading...
Dec 29, 2020 0
Participant ,
Dec 30, 2020

Copy link to clipboard

Copied

I tried ScriptListener without success: whenever I turn JPG for CameraRaw on or off, it records the same thing.

I don't know what this script is doing but it doesn't modify Photoshop settings.

 

var idsetd = charIDToTypeID( "setd" );
    var desc2 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref1 = new ActionReference();
        var idPrpr = charIDToTypeID( "Prpr" );
        var idGnrP = charIDToTypeID( "GnrP" );
        ref1.putProperty( idPrpr, idGnrP );
        var idcapp = charIDToTypeID( "capp" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref1.putEnumerated( idcapp, idOrdn, idTrgt );
    desc2.putReference( idnull, ref1 );
    var idT = charIDToTypeID( "T   " );
        var desc3 = new ActionDescriptor();
        var idlegacyPathDrag = stringIDToTypeID( "legacyPathDrag" );
        desc3.putBoolean( idlegacyPathDrag, true );
    var idGnrP = charIDToTypeID( "GnrP" );
    desc2.putObject( idT, idGnrP, desc3 );
executeAction( idsetd, desc2, DialogModes.NO );

 

Likes

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
Reply
Loading...
Dec 30, 2020 0
Adobe Community Professional ,
Dec 30, 2020

Copy link to clipboard

Copied

On the Mac, one can set the standard open options to force a supported TIFF or JPEG to open into ACR:

 

force-acr.png

 

Another approach would be to force the JPEG/TIFF to open via:

 

 

OpenDocumentType.CAMERARAW

 

 

Obviously more code is required than just that snippet, however, I couldn't get that to work, but I hacked at the following script and it did work:

 

 

//community.adobe.com/t5/photoshop/how-to-record-button-click-on-action/td-p/10858184
var forceACR = File.openDialog("Please select a JPEG or TIFF file");
var d = new ActionDescriptor();
d.putBoolean(stringIDToTypeID("dontRecord"), true);
d.putBoolean(stringIDToTypeID("forceNotify"), true);
d.putPath(stringIDToTypeID("null"), forceACR);
var d1 = new ActionDescriptor();
d.putObject(stringIDToTypeID("as"), stringIDToTypeID("Adobe Camera Raw"), d1);
d.putBoolean(stringIDToTypeID("smartObject"), true);
d.putBoolean(stringIDToTypeID("overrideOpen"), true);
executeAction(stringIDToTypeID("open"), d, DialogModes.ALL);

 

 

Likes

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
Reply
Loading...
Dec 30, 2020 1
Participant ,
Dec 30, 2020

Copy link to clipboard

Copied

Thank you for you replies.

 

Stephen, I always drag and drop images on Photoshop, so I didn't know this wonderful "Options" button in Open dialog 🙂

Your script works fine. A "try/catch" can be added to avoid an error alert if the user clicks on the Cancel button in CameraRaw:

 

//community.adobe.com/t5/photoshop/how-to-record-button-click-on-action/td-p/10858184
var forceACR = File.openDialog("Please select a JPEG or TIFF file");
var d = new ActionDescriptor();
d.putBoolean(stringIDToTypeID("dontRecord"), true);
d.putBoolean(stringIDToTypeID("forceNotify"), true);
d.putPath(stringIDToTypeID("null"), forceACR);
var d1 = new ActionDescriptor();
d.putObject(stringIDToTypeID("as"), stringIDToTypeID("Adobe Camera Raw"), d1);
d.putBoolean(stringIDToTypeID("smartObject"), true);
d.putBoolean(stringIDToTypeID("overrideOpen"), true);

try {
	executeAction(stringIDToTypeID("open"), d, DialogModes.ALL);
} catch (error) {
	// user has cancelled CameraRaw dialog
}

 

Likes

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
Reply
Loading...
Dec 30, 2020 1
Participant ,
Dec 31, 2020

Copy link to clipboard

Copied

Stephen,

Any idea about how to make your script handle several images in one pass?

Camera Raw allows to open several images, so it's possible to apply an image setting to all opened images. This feature is very convenient.

Embedding your script in a repeat structure only tells Camera Raw to open the images one by one.

Likes

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
Reply
Loading...
Dec 31, 2020 0
Adobe Community Professional ,
Dec 31, 2020

Copy link to clipboard

Copied

 

if ((fldr = Folder.selectDialog()) && (fls = fldr.getFiles(/.jpe?g$/i)).length) {
	fls.sort(function(v1, v2){return compareWithNumbers(v1.name, v2.name)})

	sTT = stringIDToTypeID; while(fls.length) {
		dsc = new ActionDescriptor(), dsc.putPath(sTT('null'), fls.shift())
		dsc.putObject(sTT('as'), sTT('Adobe Camera Raw'), new ActionDescriptor())
		for(i = 0; i < 2;) dsc.putBoolean(sTT(['smartObject', 'overrideOpen'][i++]), true)
		try{executeAction(sTT('open'), dsc, DialogModes.ALL)}catch(err){}
	}
}

 

Likes

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
Reply
Loading...
Dec 31, 2020 1
Adobe Community Professional ,
Dec 31, 2020

Copy link to clipboard

Copied

 

 

Any idea about how to make your script handle several images in one pass?

 

 

Haha, thanks for the conundrum for New Years Day fredericm80874937 !

 

The original script was from r-bin, I just removed a bit of code so that it would just open the image without applying any settings (the original script was to preset the application of the "auto" button).

 

Kukurykus gave it a good go, however, each image is opened sequentually into ACR, whereas I;m guessing that you want them to all open into the sidebar "filmstrip".

 

I'm thinking that the easiest way may be to apply metadata to the images so that they contain Camera Raw Settings and would then be processed by ACR if your settings were setup to handle the JPEG or TIFF's in ACR. My go to method would be to use ExifTool as that is relatively quick and easy compared to scripting. I'll have a play...

 

P.S. If this could be scripted, would you wish to select a folder of files and process all the files, or would you prefer to select one or more files from an open dialog (I'm guessing the second)?

 

 

 

Likes

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
Reply
Loading...
Dec 31, 2020 1
Adobe Community Professional ,
Dec 31, 2020

Copy link to clipboard

Copied

I'm thinking that the easiest way is simply to use Adobe Bridge, select multiple JPEG/TIFF files and then press CMD + R to open the files into ACR.

Likes

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
Reply
Loading...
Dec 31, 2020 0
Participant ,
Jan 01, 2021

Copy link to clipboard

Copied

Yes, indeed, I was thinking of opening all the selected images at the same time, with the ACR sidebar "filmstrip". This allows you to apply adjustments very easily and quickly to all opened images.

 

With the version of macOS I'm using (Sierra 10.12.6), Adobe Bridge has some weird effects on Photoshop, especially on the pointer, so I prefer to avoid Bridge as much as possible.

 

I didn't think it was possible to add metadata to JPEG files to make them readable by ACR. It's very interesting! However, having worked with ExifTool and PHP a few years ago, I have very bad memories. ExifTool is a very powerful tool, but very complex to use and I admit that I am a little bit reluctant to install it.

Ideally, I would prefer to add these metadata to JPEG files with Applescript and its shell script access.

Anyway, as I don't open JPEGs with ACR every day, your script is already fine with me and I thank you for that 🙂
By the way, I wrote a small Applescript (MacOS therefore) which, compiled in application, allows to open with ACR a single dropped JPEG file. I can post the code if anyone is interested.

 

And happy new year everyone!

Likes

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
Reply
Loading...
Jan 01, 2021 0
Adobe Community Professional ,
Jan 01, 2021

Copy link to clipboard

Copied

The ExifTool route is easy enough to setup and use, even more so when combined into a Mac OS service:

 

https://prepression.blogspot.com/2016/12/automator-diy-exiftool-gui-services.html

 

_____

 

For completeness, here is what I came up with for ExifTool... I was hoping to only add minimal CRS metadata, however, I only had success when adding all of it, whether or not it is applicable to a JPEG/TIFF. The code below is formatted for a Mac, Windows OS would use double straight quotes instead of single straight quotes.

 

exiftool -overwrite_original -XMP-crs:Version='12.2.1' -XMP-crs:ProcessVersion='11.0' -XMP-crs:WhiteBalance='As Shot' -XMP-crs:IncrementalTemperature='0' -XMP-crs:IncrementalTint='0' -XMP-crs:Saturation='0' -XMP-crs:Sharpness='0' -XMP-crs:LuminanceSmoothing='0' -XMP-crs:ColorNoiseReduction='0' -XMP-crs:VignetteAmount='0' -XMP-crs:ShadowTint='0' -XMP-crs:RedHue='0' -XMP-crs:RedSaturation='0' -XMP-crs:GreenHue='0' -XMP-crs:GreenSaturation='0' -XMP-crs:BlueHue='0' -XMP-crs:BlueSaturation='0' -XMP-crs:Vibrance='0' -XMP-crs:HueAdjustmentRed='0' -XMP-crs:HueAdjustmentOrange='0' -XMP-crs:HueAdjustmentYellow='0' -XMP-crs:HueAdjustmentGreen='0' -XMP-crs:HueAdjustmentAqua='0' -XMP-crs:HueAdjustmentBlue='0' -XMP-crs:HueAdjustmentPurple='0' -XMP-crs:HueAdjustmentMagenta='0' -XMP-crs:SaturationAdjustmentRed='0' -XMP-crs:SaturationAdjustmentOrange='0' -XMP-crs:SaturationAdjustmentYellow='0' -XMP-crs:SaturationAdjustmentGreen='0' -XMP-crs:SaturationAdjustmentAqua='0' -XMP-crs:SaturationAdjustmentBlue='0' -XMP-crs:SaturationAdjustmentPurple='0' -XMP-crs:SaturationAdjustmentMagenta='0' -XMP-crs:LuminanceAdjustmentRed='0' -XMP-crs:LuminanceAdjustmentOrange='0' -XMP-crs:LuminanceAdjustmentYellow='0' -XMP-crs:LuminanceAdjustmentGreen='0' -XMP-crs:LuminanceAdjustmentAqua='0' -XMP-crs:LuminanceAdjustmentBlue='0' -XMP-crs:LuminanceAdjustmentPurple='0' -XMP-crs:LuminanceAdjustmentMagenta='0' -XMP-crs:SplitToningShadowHue='0' -XMP-crs:SplitToningShadowSaturation='0' -XMP-crs:SplitToningHighlightHue='0' -XMP-crs:SplitToningHighlightSaturation='0' -XMP-crs:SplitToningBalance='0' -XMP-crs:ParametricShadows='0' -XMP-crs:ParametricDarks='0' -XMP-crs:ParametricLights='0' -XMP-crs:ParametricHighlights='0' -XMP-crs:ParametricShadowSplit='25' -XMP-crs:ParametricMidtoneSplit='50' -XMP-crs:ParametricHighlightSplit='75' -XMP-crs:SharpenRadius='+1.0' -XMP-crs:SharpenDetail='25' -XMP-crs:SharpenEdgeMasking='0' -XMP-crs:PostCropVignetteAmount='0' -XMP-crs:GrainAmount='0' -XMP-crs:LensProfileEnable='0' -XMP-crs:LensManualDistortionAmount='0' -XMP-crs:PerspectiveVertical='0' -XMP-crs:PerspectiveHorizontal='0' -XMP-crs:PerspectiveRotate='0.0' -XMP-crs:PerspectiveScale='100' -XMP-crs:PerspectiveAspect='0' -XMP-crs:PerspectiveUpright='0' -XMP-crs:PerspectiveX='0.00' -XMP-crs:PerspectiveY='0.00' -XMP-crs:AutoLateralCA='0' -XMP-crs:Exposure2012='+0.01' -XMP-crs:Contrast2012='0' -XMP-crs:Highlights2012='0' -XMP-crs:Shadows2012='0' -XMP-crs:Whites2012='0' -XMP-crs:Blacks2012='0' -XMP-crs:Clarity2012='0' -XMP-crs:DefringePurpleAmount='0' -XMP-crs:DefringePurpleHueLo='30' -XMP-crs:DefringePurpleHueHi='70' -XMP-crs:DefringeGreenAmount='0' -XMP-crs:DefringeGreenHueLo='40' -XMP-crs:DefringeGreenHueHi='60' -XMP-crs:Dehaze='0' -XMP-crs:Texture='0' -XMP-crs:ToneMapStrength='0' -XMP-crs:ConvertToGrayscale='False' -XMP-crs:OverrideLookVignette='False' -XMP-crs:ToneCurveName='Linear' -XMP-crs:ToneCurveName2012='Linear' -XMP-crs:CameraProfile='Embedded' -XMP-crs:CameraProfileDigest='' -XMP-crs:LensProfileSetup='LensDefaults' -XMP-crs:UprightVersion='' -XMP-crs:UprightCenterMode='0' -XMP-crs:UprightCenterNormX='0.5' -XMP-crs:UprightCenterNormY='0.5' -XMP-crs:UprightFocalMode='0' -XMP-crs:UprightFocalLength35mm='35' -XMP-crs:UprightPreview='False' -XMP-crs:UprightTransformCount='6' -XMP-crs:UprightFourSegmentsCount='0' -XMP-crs:HasSettings='True' -XMP-crs:HasCrop='False' -XMP-crs:AlreadyApplied='False' -XMP-crs:ToneCurve='0, 0, 255, 255' -XMP-crs:ToneCurveRed='0, 0, 255, 255' -XMP-crs:ToneCurveGreen='0, 0, 255, 255' -XMP-crs:ToneCurveBlue='0, 0, 255, 255' -XMP-crs:ToneCurvePV2012='0, 0, 255, 255' -XMP-crs:ToneCurvePV2012Red='0, 0, 255, 255' -XMP-crs:ToneCurvePV2012Green='0, 0, 255, 255' -XMP-crs:ToneCurvePV2012Blue='0, 0, 255, 255' -r 'path to/folder/or file'

 

Likes

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
Reply
Loading...
Jan 01, 2021 0
Adobe Community Professional ,
Jan 01, 2021

Copy link to clipboard

Copied

On windows edit file

C:\Users\USERNAME\AppData\Roaming\Adobe\CameraRaw\Defaults\Preferences.xmp

 

the line with: "crs:JPEGHandling="

 

On Mac find this file yourself.

Likes

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
Reply
Loading...
Jan 01, 2021 4
Adobe Community Professional ,
Jan 01, 2021

Copy link to clipboard

Copied

Ah, the backdoor approach! I like it, it is obvious in hindsight and offers a different method... It should be possible to script the editing of the XML file directly (I have tried but it is beyond my current abilities)...

 

On the Mac, it will be similar to this path:

 

/Users/user account name here/Library/Application Support/Adobe/CameraRaw/Defaults/Preferences.xmp

 

 

crs:JPEGHandling="OpenIfHasSettings"
crs:JPEGHandling="Disable"
crs:JPEGHandling="OpenIfSupported"

 

 

Likes

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
Reply
Loading...
Jan 01, 2021 1
Adobe Community Professional ,
Jan 01, 2021

Copy link to clipboard

Copied

The following script will open the folder, which is defaulted to a hidden directory on Windows OS:

 

 

/* Open ACR Defaults Folder - Universal */

#target photoshop

app.bringToFront();

openACRdefaultsDir();

function openACRdefaultsDir() {
    var os = $.os.toLowerCase().indexOf('mac') >= 0 ? "MAC" : "WINDOWS";
    if (os === 'MAC') {
        // alert("It's a Mac!");

        acrDirMac();

        function acrDirMac() {
            var acrDefaultsDirMac = '~/Library/Application Support/Adobe/CameraRaw/Defaults/'; // Preferences.xmp
            var acrDefaultsDirMacOpen = Folder(acrDefaultsDirMac);
            acrDefaultsDirMacOpen.execute();
        }

    } else {
        // alert("It's Windows!");

        acrDirWin();

        function acrDirWin() {
            var acrDefaultsDirWin = '~/AppData/Roaming/Adobe/CameraRaw/Defaults/'; // Preferences.xmp
            var acrDefaultsDirWinOpen = Folder(acrDefaultsDirWin);
            acrDefaultsDirWinOpen.execute();
        }

    }
}

 

 

P.S. If you have a suitable program set to open XML files, you can add the Preferences.xml to the end of the directory path.

 

Likes

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
Reply
Loading...
Jan 01, 2021 0
Participant ,
Jan 02, 2021

Copy link to clipboard

Copied

Great!

Thank you all for your help: I should have time this week-end to explore this very interesting possibility 🙂

I'll answer this thread when I'll have some code to show.

Likes

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
Reply
Loading...
Jan 02, 2021 0
Adobe Community Professional ,
Jan 02, 2021

Copy link to clipboard

Copied

Well, it only becomes interesting (for me) if you can figure out how to script writing a value (below) to an XML file.

 

crs:JPEGHandling="OpenIfHasSettings"
crs:JPEGHandling="Disable"
crs:JPEGHandling="OpenIfSupported"

Likes

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
Reply
Loading...
Jan 02, 2021 1
Participant ,
Jan 02, 2021

Copy link to clipboard

Copied

I don't understand anything to these weird xmp Adobe preferences files, so I wrote an ugly script that modifies JPEGHandling value by replacing all ACR preferences file as text.

 

It's a simple switch that allows to turn on or off JPEGHandling :

// ------------------------------------------- settings
var userPref = 'jpeg'; /////
var scriptName = 'Camera Raw - Files to open';
var rawOpenPrefs = {'jpeg': 'crs:JPEGHandling', 'tiff': 'crs:TIFFHandling'}; // some ACR prefs

/* ACR open JPEG or TIFF files
	crs:JPEGHandling="OpenIfHasSettings" // open if file have some special meta tags
	crs:JPEGHandling="Disable" // never open
	crs:JPEGHandling="OpenIfSupported" // open almost all files
*/
var rawOpenState = {'Disable': false, 'OpenIfHasSettings': false, 'OpenIfSupported': true};
var rawOpenValues = {'yes': 'OpenIfSupported', 'no': 'OpenIfHasSettings'};

// ------------------------------------------- prompt
var ACRprefsFile = getACRprefsPath();
var prefsStr = ''; // will contains ACR prefs file string
var actualStrValue = '';

promptACRopenFile();

function promptACRopenFile() {
	if (!fileExists(ACRprefsFile)) {
		alert(scriptName + "\n" + 'ACR preferences file not found.'); // to do: create ACR prefs file?
		return false;
	}
	
	prefsStr = readFromFile(ACRprefsFile); // ACR prefs file content (string), or false if error
	if (prefsStr == false) {
		alert(scriptName + "\n" + 'Unable to read ACR preferences file.');
		return false;
	}

	var actualState = readACRopenPrefs(userPref);
//alert('ACR ' + userPref + ' opening state: ' + actualState);/////
	if (!actualState) {
		if (confirm(scriptName + "\n" + 'Camera Raw does NOT open ' + userPref + ' files.' + "\n" + 'Would you like to let Camera Raw open these files?')) {
			var result = setRawPrefsValue(userPref, true);
			if (result != '') alert(scriptName + "\n" + 'Unable to write new preferences:' + "\n" + '    ' + result);
		}
	}else{
		if (confirm(scriptName + "\n" + 'Camera Raw can open ' + userPref + ' files.' + "\n" + 'Would you like to no longer let Camera Raw open these files?')) {
			var result = setRawPrefsValue(userPref, false);
			if (result != '') alert(scriptName + "\n" + 'Unable to write new preferences:' + "\n" + '    ' + result);
		}
	}
}

// ------------------------------------------- read/write ACR prefs file
function readACRopenPrefs(fileKind) {
	// ----- returns actual value (boolean), or error string
	var actualOpenFilePrefs = getRawPrefsValue(fileKind);
	if (typeof actualOpenFilePrefs == 'boolean') {
		return actualOpenFilePrefs;
	}else{
		alert(scriptName + "\n" + 'An error has occured: ' + actualOpenFilePrefs);
	}
}

function getRawPrefsValue(nodeName) {
	// ----- returns boolean value, or error string
	var objPrefValue = getRawPrefsLine(nodeName);
	if (objPrefValue.error != '') {
		return objPrefValue.error;
	}else{
		if (objPrefValue.line == 0) {
			return "Node '" + nodeName + "' not found.";
		}else{
//alert('line#=' + objPrefValue.line + "\n" + 'value=' + objPrefValue.value + "\n" + 'item 2=' + getItem(objPrefValue.value, '=', 2));/////
			var actualPrefValue = fullTrim(getItem(objPrefValue.value, '=', 2));
			actualPrefValue = strReplace(actualPrefValue, '"', '', false);
//alert('actualPrefValue#=' + actualPrefValue);/////
			if (rawOpenState.hasOwnProperty(actualPrefValue)) {
				actualStrValue = actualPrefValue;
				return rawOpenState[actualStrValue];
			}else{
				return 'unknown value.';
			}
		}
	}
}

function getRawPrefsLine(nodeName) { // get line number and value
	// ------- returns object: {'line', 'value': null, 'error'}
	var objResult = {'line': 0, 'value': null, 'error' : ''}
	
	if (rawOpenPrefs.hasOwnProperty(nodeName)) {
		var arrPrefs = prefsStr.split("\n");
		if (arrPrefs.length >= 10) {
			for (i = 0; i < arrPrefs.length; i++) {
				if (arrPrefs[i].indexOf(rawOpenPrefs[nodeName], 0) > -1) {
					objResult.line = i;
					objResult.value = arrPrefs[i];
					break;
				}
			}
		}else{
			objResult.error = 'ACR preferences error';
		}
	}else{
		objResult.error = "Node '" + nodeName + "' not defined.";
	}
	
	return objResult;
}

function setRawPrefsValue(nodeName, newValue) {
	// ----- returns '' or error string
	var newValue = newValue || false;
	
	var oldString = rawOpenPrefs[nodeName] + '="' + actualStrValue + '"';
	var newString = rawOpenPrefs[nodeName] + '="' + ((newValue)? rawOpenValues.yes : rawOpenValues.no) + '"';
//alert('newValue=' + newValue + "\n" + 'old=' + oldString + "\n" + '-->' + rawOpenValues.no + "\n" + 'new=' + newString + "\n" + 'indexOf=' + prefsStr.indexOf(oldString));/////
	var newPrefsStr = prefsStr.replace(oldString, newString); // first occurence only
	
	return writeToFile(ACRprefsFile, newPrefsStr);
}

function getACRprefsPath() {
	// ------ returns path to ACR prefs file, depending of OS
	return (File.fs == 'Macintosh')? '~/Library/Application Support/Adobe/CameraRaw/Defaults/Preferences.xmp' : '~/AppData/Roaming/Adobe/CameraRaw/Defaults/Preferences.xmp';
}

function fileExists(fileName) {
	// ------ returns true if file fileName exists
	if (fileName == 'undefined' || fileName === undefined || fileName == '') return false;
	var filePointer = new File(fileName);
    return filePointer.exists;
}

function readFromFile(fileName) {
	// ------ returns file content (string), or false if error
	var filePointer = new File(fileName);
	try {
		filePointer.open('r', "UTF-8"); // 'r' = read-only
		var str = filePointer.read();
		filePointer.close();
		return str;
	}catch (err){
		return false;
	}
}

function writeToFile(fileName, str) {
	// ---- replace actual file content, and returns '', or error string
	try {
		var filePointer = new File(fileName);
		filePointer.encoding = "UTF8";
		filePointer.open('w'); // 'a' for append
		filePointer.write(str);
		filePointer.close();
		return '';
	}catch (err){
		return err;
	}
}

function getItem(str, delimiter, itemNumber) { // starts from 1
	if (str === null) return str;
	var itemNumber = itemNumber || 1;
	if ((typeof delimiter == 'undefined') || (delimiter === undefined) || delimiter == '') return str;
	
	var arr = str.toString().split(delimiter);
	var arrLength = arr.length;
	if (arrLength >= (itemNumber - 1)) {
		return arr[Math.min(arrLength - 1, Math.max(0, itemNumber - 1))];
	}else{
		return str;
	}
}

function fullTrim(str) { // also replace multiples spaces by single space inside passed string
	if (str === null) return str;
	return str.replace(/^\s+|\s+$/g,'');
}

function strReplace(string, oldStr, newStr, caseSensitive) {
	// ---- replace ALL occurences
	if (string === null) return string;
	if ((typeof caseSensitive == 'undefined') || (caseSensitive === undefined)) caseSensitive = false;
	var regex = (caseSensitive == true)? new RegExp(oldStr, "g") : new RegExp(oldStr,"gi");
	return string.replace(regex,newStr);
}

 

It has only been tested with Photoshop CS 6 on MacOS Sierra.

 

At this point, I have an Applescript droplet to open a single JPEG file with Camera Raw, and also a Javascript switch. So, Im' happy because that's all what I needed 🙂

Likes

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
Reply
Loading...
Jan 02, 2021 1
Adobe Community Professional ,
Jan 02, 2021

Copy link to clipboard

Copied

A tantalising glimpse of another possibility here from Kukurykus:

 

https://www.ps-scripts.com/viewtopic.php?f=66&t=40499&p=169250&hilit=xml#p169250

 

Likes

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
Reply
Loading...
Jan 02, 2021 1
Adobe Community Professional ,
Jan 02, 2021

Copy link to clipboard

Copied

You probably find it in:

File(preferencesFolder.fullName + '/' + (bt = BridgeTalk).getDisplayName(bt.appSpecifier) + ' Prefs.psp')

Likes

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
Reply
Loading...
Jan 02, 2021 2