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

Script to open the last closed file.

Contributor ,
Feb 19, 2020 Feb 19, 2020

Copy link to clipboard

Copied

Hello! How to recover "open" only the last closed document.
It's possible?
Thanks.

TOPICS
Actions and scripting

Views

1.7K

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

Guide , Feb 20, 2020 Feb 20, 2020

You could try....

#target photoshop;
app.bringToFront();

var f = File(recentFilePaths()[0]);
if(f.exists) open(f); else alert("Sorry " + f.fsName + " does not now exit");

function recentFilePaths(){
var names = [];
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr"), stringIDToTypeID("recentFiles") );
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var desc = executeActionGet(ref).getList(stringIDToTypeID("recentFiles"));
for(va
...

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 19, 2020 Feb 19, 2020

Copy link to clipboard

Copied

You would most likely have to write a script to keep track of what was last closed. So you would run the script to close the file, then it would write the file's info to a csv file, which could then be accessed to open it with a different 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
Contributor ,
Feb 20, 2020 Feb 20, 2020

Copy link to clipboard

Copied

This is a topic never addressed, never seen in any community.
Interesting your idea Chuck Uebele, but I would never be able to do it alone, I know the least about scripting, it would be a great impolite of me to abuse your kindness to achieve this!
A good alternative would be:
If I open a file and then close it, it has been registered in the menu list "Open Recent". I would only need the first item on that list.

Anotação 2020-02-20 123420.png
I entered this modified script: It didn't work for me: Window 10 Photoshop 21.0.0

 

 

#target photoshop
app.bringToFront();
var maxFiles = 1;
var recentItems = [];
var len = recentFiles.length;
for (var i = 0; i < len; i++)
{
    recentFile = recentFiles;
    if (recentFile.exists)
    {
        recentItems.push(recentFile);
        if (recentItems.length == maxFiles+1)
        {
            break;
        }
        app.open (File(recentItems));
    }
}

 

 

Source:
https://community.adobe.com/t5/photoshop/script-for-quot-open-recent-quot/td-p/7378756?page=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
People's Champ ,
Feb 20, 2020 Feb 20, 2020

Copy link to clipboard

Copied

The first item on this list is not the last closed file.

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
Contributor ,
Feb 20, 2020 Feb 20, 2020

Copy link to clipboard

Copied

Hi r-bin, regardless of whether it is the last file or not, It would be nice to open only the first item on the list. Would you have any ideas? Please share

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 ,
Feb 20, 2020 Feb 20, 2020

Copy link to clipboard

Copied

if (recentFiles.length) app.open(recentFiles[0]);

 

UPD.

if (recentFiles.length && recentFiles[0].exists) app.open(recentFiles[0]);

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
Guide ,
Feb 20, 2020 Feb 20, 2020

Copy link to clipboard

Copied

You could try....

#target photoshop;
app.bringToFront();

var f = File(recentFilePaths()[0]);
if(f.exists) open(f); else alert("Sorry " + f.fsName + " does not now exit");

function recentFilePaths(){
var names = [];
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr"), stringIDToTypeID("recentFiles") );
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var desc = executeActionGet(ref).getList(stringIDToTypeID("recentFiles"));
for(var a = 0;a<desc.count;a++){
    names.push(desc.getPath(a));
    }
return names;
};

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
Contributor ,
Feb 21, 2020 Feb 21, 2020

Copy link to clipboard

Copied

LATEST

Man, that's all I need! SuperMerlin you were phenomenal. How nice to know that you still go to and share your knowledge with this modified community. Eternally grateful.

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