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

Copy and Paste Guides - Photoshop 2024

New Here ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

I had a script that worked in photoshop 23 where I could copy and paste guides from one document to another, but it is not working in the new version of Photoshop.  Does anyone have an updated script or know how to fix this problem? 

TOPICS
Actions and scripting , macOS

Views

3.0K

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

People's Champ , May 04, 2024 May 04, 2024
quote

Sorry, it’s reported on line 53. Here are lines 52 and 53 for context from the previous code posted:

 

 

 

 

 

var desc1 = app.getCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66');
var layerGuides = eval(desc1.getString(0));

 

 

 


By @Stephen Marsh

 

 
Could you use a key value other than 0 when using the putString and getString function?
It seems that the getCustomOptions function still returns the found descriptor and does not generate an error.
Many built-in scripts use the putCustomOptions and getCus
...

Votes

Translate

Translate
Adobe
Community Expert ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

Learn how to copy guides in Adobe Photoshop. This will be helpful for you to copy the guides to another document. INFO ----------- 🌐 Download the JavaScript: https://bit.ly/CopyGuides 📌 Please TURN ON CAPTIONS for instructions 🔔 Please SUBSCRIBE and click the BELL icon for NOTIFICATIONS! FOLLO...

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
Community Expert ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

Here is the script which works to copy guides in 2021:

 

/* 
https://www.reflections-ibs.com/blog/articles/how-to-copy-guides-from-one-photoshop-document-to-another
https://www.reflections-ibs.com/media/1241/guides-copy.jsx
*/
#target photoshop
main();
function main(){
if(Number(app.version.match(/\d+/)) <12) return;
if(!documents.length) return;
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
    setGuides();
app.preferences.rulerUnits = startRulerUnits;
function setGuides(){
var guides = app.activeDocument.guides;
if(guides.length == 0){
    alert("No guides exist");
    return;
    }
var gH = '';
var gV = '';
for( var g = 0; g < guides.length; g++ ){
    if(guides[g].direction.toString() == 'Direction.HORIZONTAL'){
        gH+=(parseInt(guides[g].coordinate.value));
        gH+=',';
        }else{
            gV+=(parseInt(guides[g].coordinate.value));
            gV+=','
            }
}
gH=gH.replace(/,$/,'');
gV=gV.replace(/,$/,'');
currentGuides = 'Layer Guides' + "�" + gH + "�" + gV;
var desc2 = new ActionDescriptor();
desc2.putString(0, currentGuides.toSource()); 
app.putCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66', desc2, true );
}
function displayGuides(){
try{
var desc1 = app.getCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66');
var layerGuides = eval(desc1.getString(0));
    }catch(e){return;}
clearGuides();
var ar1 = layerGuides.toString().split('�');
var Hor = ar1[1].toString().split(',');
var Ver = ar1[2].toString().split(',');
for(var H in Hor){
    activeDocument.guides.add(Direction.HORIZONTAL,new UnitValue(Number(Hor[H]),'px'));
    }
for(var V in Ver){
    activeDocument.guides.add(Direction.VERTICAL,new UnitValue(Number(Ver[V]),'px'));
    }
}
}
function clearGuides() { 
   var id556 = charIDToTypeID( "Dlt " ); 
       var desc102 = new ActionDescriptor(); 
       var id557 = charIDToTypeID( "null" ); 
           var ref70 = new ActionReference(); 
           var id558 = charIDToTypeID( "Gd  " ); 
           var id559 = charIDToTypeID( "Ordn" ); 
           var id560 = charIDToTypeID( "Al  " ); 
           ref70.putEnumerated( id558, id559, id560 ); 
       desc102.putReference( id557, ref70 ); 
   executeAction( id556, desc102, DialogModes.NO ); 
};

 

 

 

Here is the script to paste:

 

/* 
https://www.reflections-ibs.com/blog/articles/how-to-copy-guides-from-one-photoshop-document-to-another
https://www.reflections-ibs.com/media/1242/guides-paste.jsx
*/
#target photoshop
main();
function main(){
if(Number(app.version.match(/\d+/)) <12) return;
if(!documents.length) return;
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
displayGuides();
app.preferences.rulerUnits = startRulerUnits;
function setGuides(){
var guides = app.activeDocument.guides;
if(guides.length == 0){
    alert("No guides exist");
    return;
    }
var gH = '';
var gV = '';
for( var g = 0; g < guides.length; g++ ){
    if(guides[g].direction.toString() == 'Direction.HORIZONTAL'){
        gH+=(parseInt(guides[g].coordinate.value));
        gH+=',';
        }else{
            gV+=(parseInt(guides[g].coordinate.value));
            gV+=','
            }
}
gH=gH.replace(/,$/,'');
gV=gV.replace(/,$/,'');
currentGuides = 'Layer Guides' + "�" + gH + "�" + gV;
var desc2 = new ActionDescriptor();
desc2.putString(0, currentGuides.toSource()); 
app.putCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66', desc2, true );
}
function displayGuides(){
try{
var desc1 = app.getCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66');
var layerGuides = eval(desc1.getString(0));
    }catch(e){return;}
clearGuides();
var ar1 = layerGuides.toString().split('�');
var Hor = ar1[1].toString().split(',');
var Ver = ar1[2].toString().split(',');
for(var H in Hor){
    activeDocument.guides.add(Direction.HORIZONTAL,new UnitValue(Number(Hor[H]),'px'));
    }
for(var V in Ver){
    activeDocument.guides.add(Direction.VERTICAL,new UnitValue(Number(Ver[V]),'px'));
    }
}
}
function clearGuides() { 
   var id556 = charIDToTypeID( "Dlt " ); 
       var desc102 = new ActionDescriptor(); 
       var id557 = charIDToTypeID( "null" ); 
           var ref70 = new ActionReference(); 
           var id558 = charIDToTypeID( "Gd  " ); 
           var id559 = charIDToTypeID( "Ordn" ); 
           var id560 = charIDToTypeID( "Al  " ); 
           ref70.putEnumerated( id558, id559, id560 ); 
       desc102.putReference( id557, ref70 ); 
   executeAction( id556, desc102, DialogModes.NO ); 
};

 

 

 

While this version is combined, run the script with SHIFT held down to copy, run the same script again on the new doc to paste:

 

/*
https://gist.github.com/codyjlandstrom/5fcb2779b59eb97d862311a2b2815791
https://youtu.be/ERHbxtyOJEg
NOTE: Hold down the shift key when copying guides
*/

#target photoshop
main();
function main() {
    if (Number(app.version.match(/\d+/)) < 12) return;
    if (!documents.length) return;
    var startRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;

    if (ScriptUI.environment.keyboardState.shiftKey) {
        setGuides();
        app.beep();

    } else {
        displayGuides();
    }

    app.preferences.rulerUnits = startRulerUnits;

    function setGuides() {
        var guides = app.activeDocument.guides;
        if (guides.length == 0) {
            alert("No guides exist");
            return;
        }
        var gH = '';
        var gV = '';
        for (var g = 0; g < guides.length; g++) {
            if (guides[g].direction.toString() == 'Direction.HORIZONTAL') {
                gH += (parseInt(guides[g].coordinate.value));
                gH += ',';
            } else {
                gV += (parseInt(guides[g].coordinate.value));
                gV += ','
            }
        }
        gH = gH.replace(/,$/, '');
        gV = gV.replace(/,$/, '');
        currentGuides = 'Layer Guides' + "¬" + gH + "¬" + gV;
        var desc2 = new ActionDescriptor();
        desc2.putString(0, currentGuides.toSource());
        app.putCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66', desc2, true);
    }

    function displayGuides() {
        try {
            var desc1 = app.getCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66');
            var layerGuides = eval(desc1.getString(0));
        } catch (e) { return; }
        clearGuides();
        var ar1 = layerGuides.toString().split('¬');
        var Hor = ar1[1].toString().split(',');
        var Ver = ar1[2].toString().split(',');
        for (var H in Hor) {
            activeDocument.guides.add(Direction.HORIZONTAL, new UnitValue(Number(Hor[H]), 'px'));
        }
        for (var V in Ver) {
            activeDocument.guides.add(Direction.VERTICAL, new UnitValue(Number(Ver[V]), 'px'));
        }
    }
}

function clearGuides() {
    var id556 = charIDToTypeID("Dlt ");
    var desc102 = new ActionDescriptor();
    var id557 = charIDToTypeID("null");
    var ref70 = new ActionReference();
    var id558 = charIDToTypeID("Gd  ");
    var id559 = charIDToTypeID("Ordn");
    var id560 = charIDToTypeID("Al  ");
    ref70.putEnumerated(id558, id559, id560);
    desc102.putReference(id557, ref70);
    executeAction(id556, desc102, DialogModes.NO);
};

 

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
Community Expert ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

I am a little out of my depth...

 

I believe that the script is working correctly to copy the guide coordinates, as I get the expected result when I alert the following block of code from:

 

for( var g = 0; g < guides.length; g++ ){
    if(guides[g].direction.toString() == 'Direction.HORIZONTAL'){
        gH+=(parseInt(guides[g].coordinate.value));
        gH+=',';
        }else{
            gV+=(parseInt(guides[g].coordinate.value));
            gV+=','
            }
}

 

To:

 

for( var g = 0; g < guides.length; g++ ){
    if(guides[g].direction.toString() == 'Direction.HORIZONTAL'){
        alert(gH+=(parseInt(guides[g].coordinate.value)));
        gH+=',';
        }else{
            alert(gV+=(parseInt(guides[g].coordinate.value)));
            gV+=','
            }
}

 

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
Community Expert ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

This block of code looks like an Action Manager method to set a Photoshop environment "session" variable:

 

gH = gH.replace(/,$/, '');
        gV = gV.replace(/,$/, '');
        currentGuides = 'Layer Guides' + "¬" + gH + "¬" + gV;
        var desc2 = new ActionDescriptor();
        desc2.putString(0, currentGuides.toSource());
        app.putCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66', desc2, true);

 

While this looks like the corresponding code to get the variable:

 

var desc1 = app.getCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66');
var layerGuides = eval(desc1.getString(0));

 

Putting an alert into the try/catch for getting the session variable results in an error "The requested property does not exist"...

 

So the issue appears to be that v2024 has changed how AM environment variables are handled!



EDIT:

I am having issues replacing the AM code with DOM code for $.setenv() and $.getenv() to verify if this fixes the issue. Can somebody with more knowledge and/or experience please step in and help? Environment variables have always been problematic for me, I usually write to/read from a text file as a "bullet-proof" alternative.

 

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
People's Champ ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

quote

Putting an alert into the try/catch for getting the session variable results in an error "The requested property does not exist"...


By @Stephen Marsh
 
What exact code (line) causes this error?

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
Community Expert ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

@r-bin – thank you for taking an interest.

 

Error: The requested property does not exist. 53

 

Sorry, it’s reported on line 53. Here are lines 52 and 53 for context from the previous code posted:

 

 

var desc1 = app.getCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66');
var layerGuides = eval(desc1.getString(0));

 

 

This is why I believe the AM code for an environment variable is the issue in 2024. Not knowing about AM environment variables, I thought that just using a DOM environment variable would be a quick fix, but I have only had intermittent success using them.

 

There is another error generated:

 

Error 21: undefined is not an object.

Line: 56

->          var ar1 = layerGuides.toString().split('¬');

 

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
LEGEND ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

I have code someplace that uses env variables.

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
Community Expert ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

That's great, I have always had spotty results with them, writing to a text file and reading from the text file has always worked better for me, in addition to being persistent between Photoshop sessions.

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
People's Champ ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

quote

Sorry, it’s reported on line 53. Here are lines 52 and 53 for context from the previous code posted:

 

 

 

 

 

var desc1 = app.getCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66');
var layerGuides = eval(desc1.getString(0));

 

 

 


By @Stephen Marsh

 

 
Could you use a key value other than 0 when using the putString and getString function?
It seems that the getCustomOptions function still returns the found descriptor and does not generate an error.
Many built-in scripts use the putCustomOptions and getCustomOptions functions.
If the reason is their incorrect operation, then they may also stop working correctly.
These include Fit Image.jsx, Export Layers To Files.jsx and many others.
If getCustomOptions does not work in these scripts, then this is an obvious bug that needs to be fixed.
 
ADD.
Also try using putCustomOptions without "true" as the third argument,
i.e. use only the first two - name and descriptor.
 
 
 

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
Community Expert ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

@r-bin = genius – changing 0 to 1 worked!

 

desc2.putString(1, currentGuides.toSource());

 

var layerGuides = eval(desc1.getString(1));
 
P.S. I'm still interested to see how the AM environment variable would be constructed in DOM code.

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
Community Expert ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

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
LEGEND ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

This is a sample prototype, you would need to loop through the document.guides object and parse each entry. Document.guides is an object, not an array, so starting index is one, not zero. Run with your source file in the foreground (active) and your target file in the background. This works in PS 25.7.

 

 

#target photoshop

try{
    var doc = app.activeDocument;
    var g = doc.guides;
    var d = g[1].direction;
    var c = g[1].coordinate;
    var doc2 = app.documents[1];
    app.activeDocument = doc2;
    doc2.guides.add(d, c);
    }
catch(e){
    Window.alert(e + e.line);
    }

 

 

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
Community Expert ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

@Lumigraphics – Thanks for the reply, can you help with swapping AM environment variables into DOM? I believe that this is the issue with the original code that I posted earlier.

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
Explorer ,
May 03, 2024 May 03, 2024

Copy link to clipboard

Copied

I can confirm that it's not working with the newest update, version 2024.  

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
Explorer ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

@Stephen Marsh 

 

Not working on from the 2-3 updates back. Photoshop 2024.  It's now 4th of May 2024.
This is the script I was using and it's NOT working. It's the same as you posted as working.

 

COPY:

 

 

#target photoshop
main();
function main(){
if(Number(app.version.match(/\d+/)) <12) return;
if(!documents.length) return;
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
setGuides();
app.preferences.rulerUnits = startRulerUnits;
function setGuides(){
var guides = app.activeDocument.guides;
if(guides.length == 0){
alert("No guides exist");
return;
}
var gH = '';
var gV = '';
for( var g = 0; g < guides.length; g++ ){
if(guides[g].direction.toString() == 'Direction.HORIZONTAL'){
gH+=(parseInt(guides[g].coordinate.value));
gH+=',';
}else{
gV+=(parseInt(guides[g].coordinate.value));
gV+=','
}
}
gH=gH.replace(/,$/,'');
gV=gV.replace(/,$/,'');
currentGuides = 'Layer Guides' + "¬" + gH + "¬" + gV;
var desc2 = new ActionDescriptor();
desc2.putString(0, currentGuides.toSource());
app.putCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66', desc2, true );
}
function displayGuides(){
try{
var desc1 = app.getCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66');
var layerGuides = eval(desc1.getString(0));
}catch(e){return;}
clearGuides();
var ar1 = layerGuides.toString().split('¬');
var Hor = ar1[1].toString().split(',');
var Ver = ar1[2].toString().split(',');
for(var H in Hor){
activeDocument.guides.add(Direction.HORIZONTAL,new UnitValue(Number(Hor[H]),'px'));
}
for(var V in Ver){
activeDocument.guides.add(Direction.VERTICAL,new UnitValue(Number(Ver[V]),'px'));
}
}
}
function clearGuides() {
var id556 = charIDToTypeID( "Dlt " );
var desc102 = new ActionDescriptor();
var id557 = charIDToTypeID( "null" );
var ref70 = new ActionReference();
var id558 = charIDToTypeID( "Gd " );
var id559 = charIDToTypeID( "Ordn" );
var id560 = charIDToTypeID( "Al " );
ref70.putEnumerated( id558, id559, id560 );
desc102.putReference( id557, ref70 );
executeAction( id556, desc102, DialogModes.NO );
};

 

 

PASTE:

 

#target photoshop
main();
function main(){
if(Number(app.version.match(/\d+/)) <12) return;
if(!documents.length) return;
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
displayGuides();
app.preferences.rulerUnits = startRulerUnits;
function setGuides(){
var guides = app.activeDocument.guides;
if(guides.length == 0){
alert("No guides exist");
return;
}
var gH = '';
var gV = '';
for( var g = 0; g < guides.length; g++ ){
if(guides[g].direction.toString() == 'Direction.HORIZONTAL'){
gH+=(parseInt(guides[g].coordinate.value));
gH+=',';
}else{
gV+=(parseInt(guides[g].coordinate.value));
gV+=','
}
}
gH=gH.replace(/,$/,'');
gV=gV.replace(/,$/,'');
currentGuides = 'Layer Guides' + "¬" + gH + "¬" + gV;
var desc2 = new ActionDescriptor();
desc2.putString(0, currentGuides.toSource());
app.putCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66', desc2, true );
}
function displayGuides(){
try{
var desc1 = app.getCustomOptions('7a301ec0-afde-11e1-afa6-0800200c9a66');
var layerGuides = eval(desc1.getString(0));
}catch(e){return;}
clearGuides();
var ar1 = layerGuides.toString().split('¬');
var Hor = ar1[1].toString().split(',');
var Ver = ar1[2].toString().split(',');
for(var H in Hor){
activeDocument.guides.add(Direction.HORIZONTAL,new UnitValue(Number(Hor[H]),'px'));
}
for(var V in Ver){
activeDocument.guides.add(Direction.VERTICAL,new UnitValue(Number(Ver[V]),'px'));
}
}
}
function clearGuides() {
var id556 = charIDToTypeID( "Dlt " );
var desc102 = new ActionDescriptor();
var id557 = charIDToTypeID( "null" );
var ref70 = new ActionReference();
var id558 = charIDToTypeID( "Gd " );
var id559 = charIDToTypeID( "Ordn" );
var id560 = charIDToTypeID( "Al " );
ref70.putEnumerated( id558, id559, id560 );
desc102.putReference( id557, ref70 );
executeAction( id556, desc102, DialogModes.NO );
};

 

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
Community Expert ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

@filips97187540 

 

Thanks for confirming, other scripted options still work (see my previous post), so at least there are alternatives.

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
Explorer ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

@Stephen Marsh  Can you point me at one that works with the recent PS2024 version? I'll test it right away.

 

 

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
Community Expert ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

They both work in 2024 as they are not leveraging an environment variable. This one copies the guides to all open docs in a single step:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/copy-guides-across-documents/td-p/140...

 

While this one is the equivalent of the broken one:

 

Export Guides - Photoshop.jsx

 

if (documents.length == 0) {
    alert("There are no documents open.");
}
else {
    var docRef = activeDocument;
    
    
    if ($.os.search(/windows/i) != -1) {
    fileLineFeed = "Windows"
    } else {
    fileLineFeed = "Macintosh"
    }

    fileOut = new File("~/Desktop/Guides.txt")
    fileOut.lineFeed = fileLineFeed
    fileOut.open("w", "TEXT", "????")

    for(var i=0; i<docRef.guides.length; ++i) {
        fileOut.write(docRef.guides[i].direction + "," + docRef.guides[i].coordinate + "\n")
    }
    fileOut.close();
    alert("Guides exported!");
}

 

 

Import Guides - Photoshop.jsx

 

if (documents.length == 0) {
    alert("There are no documents open.");
}
else {
    var docRef = activeDocument;
    
    
    if ($.os.search(/windows/i) != -1) {
    fileLineFeed = "Windows"
    } else {
    fileLineFeed = "Macintosh"
    }

    fileOut = new File("~/Desktop/Guides.txt")
    fileOut.lineFeed = fileLineFeed
    fileOut.open("r", "TEXT", "????")
    var line = "";
    while((line = fileOut.readln()) !== "")
    {
            var dir = line.split(",")[0];
            var amt = line.split(",")[1].split(" ")[0];
            var unit = line.split(",")[1].split(" ")[1];
            var cmd = "docRef.guides.add("+dir+",UnitValue("+amt+","+"\""+unit+"\"))";
            eval(cmd);
    }
    fileOut.close();
    alert("Guides imported!");
}

fileOut.remove(); // Remove the text file from the desktop

 

I added an extra line at the end to delete the text file after importing, simply remove that last line if you wish to import the same guides to multiple documents.

 

The two separate scripts could be combined into a single script where the SHIFT or OPT/ALT key is used to copy.

 

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
Explorer ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

@Stephen Marsh  

 

Thanks, It works in the newest PS2024!

I just deleted alert  cause that's one click more then I need. And I renemaed Export script to COPY and Import script to PASTE, it kinda makes more sence to me.

 

Thank you very much!

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
Community Expert ,
May 04, 2024 May 04, 2024

Copy link to clipboard

Copied

quote

@Stephen Marsh  

 

Thanks, It works in the newest PS2024!

I just deleted alert  cause that's one click more then I need.


By @filips97187540

 

You're welcome!

 

I usually use an app.beep(); if I want quick feedback that something worked without having to OK an alert.

 

P.S. @r-bin has provided info on fixing the original script and it now works for me in 2024 and when tested in 2021 it still worked with the same fix!

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
Explorer ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

Can you post the fixed old script?

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
Community Expert ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

@filips97187540 

 

I'm on a mobile phone at the moment, so no. But it's as I previously wrote, just find the following two bits in the script changing 0 to 1:

 

desc2.putString(1, currentGuides.toSource());

 

var layerGuides = eval(desc1.getString(1));

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
Explorer ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

LATEST

Works here to, BUT it added one more guide at the top of the format, horizontal one.... Not sure why. I will rather stick with the new script for PS2024. Just to be sure.

 

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