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

savedialog without overwrite question or with overwrite / append / cancel

Contributor ,
Dec 25, 2018 Dec 25, 2018

Hi,

I have a script that takes some input, then processes the current file and writes a log of its activities. The script suggests to use

<filename>-changes.txt for <filename>.ai.

If the script is run more than once (with different input params) it makes sense to append to the existing log file, so it is opened in append mode.

Now, savedialog asks whether I want to overwrite or cancel ... and if I accept overwrite, the script nevertheless succeeds to append.

While I could live with that, it is pretty hard to explain this counter intuitive behaviour to my graphics colleague....

TOPICS
Scripting
2.0K
Translate
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

Advocate , Jan 02, 2019 Jan 02, 2019

Hi,

Je n'avais pas bien compris le problème, il s'agit donc d'éviter
      le message 'Remplacer le fichier' de saveDlg.

      J'ai trouvé une piste pour éviter cette fonction des objets File.

      Utiliser :

1    selectDlg qui pointera sur le répertoire doc.path (l'utilisateur peut choisir un autre dossier)  

2    Avertir l'utilisateur de l'existence ou non du fichier 'myDoc-changed.txt'.  

3    getFiles("*.txt") pour constituer la liste des fichiers .txt  

4    new Window('dialog' avec une 'dropdo

...
Translate
Adobe
Community Expert ,
Dec 26, 2018 Dec 26, 2018

can you share your code or maybe a screencapture of the behavior you're describing? i'm not following.

Translate
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 ,
Dec 26, 2018 Dec 26, 2018

Hi,

the relevant part of some dummy code is here; the real script accepts a pattern and actually modifies symbols whose name matches.

var doc = app.activeDocument;

var sym = doc.symbols;

var fn = doc.fullName.fsName;

var tfn = new File(fn.replace('.ai', '-changed.txt'));

// here comes some UI part that would input a pattern and finally call

var pattern new RegExp('shape[0-9]{3}');

doit();

function doit()

{       log = tfn.saveDlg("Process - save / append log to?");

        if(!log) return;

        log.open('a');

// do the actual work here - here is dummy

        for(var n = 0 ; n < sym.length ; n++)

                log.writeln(sym.name);

        log.close();

}

When run for the first time, it suggests a file name, and clicking Save is fine. Now, the second time through,

one would still click Save, but since the file exists, the system would prompt for overwrite. Now,

actually accepting the overwrite leads to the log.open('a') line.

Well, I can check for existance of the recommended file and alert the user to ignore the next question

Translate
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
Advocate ,
Dec 29, 2018 Dec 29, 2018

Salut !

Is it possible to agree ?

  doit(tfn,true);

function doit(log,clear) {

    if (log.exists) {

      if(!confirm(log+"\rThis file exists, want to replace it ?")) {

        return;

      }

      else {

        if (clear) log.remove ();  //If clear content

      }

    }

  log = log.saveDlg("Process - save / append log to?","txt:*.txt");

    if(!log) return;

  log.open('a');

  // do the actual work here - here is dummy

    for(var n = 0 ; n < sym.length ; n++) {

      log.writeln(sym.name);

    }

  log.close();

}

de elleere

Translate
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 ,
Dec 29, 2018 Dec 29, 2018

Hi,

thanks for the suggestion. Unfortunately, expected user behaviour is to accept the suggested filename (and append to the file if used more than once). Alternate user behaviour could be to put the file into a different folder or to choose a common file to collect change messages from a group of related files. So I would still trigger the (somewhat useless but still annoying) system default overwrite dialog.

The only situation where somebody might wish to replace the log would be starting over again, possibly with a backup copy of the AI file

Translate
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
Advocate ,
Jan 02, 2019 Jan 02, 2019

Hi,

Je n'avais pas bien compris le problème, il s'agit donc d'éviter
      le message 'Remplacer le fichier' de saveDlg.

      J'ai trouvé une piste pour éviter cette fonction des objets File.

      Utiliser :

1    selectDlg qui pointera sur le répertoire doc.path (l'utilisateur peut choisir un autre dossier)  

2    Avertir l'utilisateur de l'existence ou non du fichier 'myDoc-changed.txt'.  

3    getFiles("*.txt") pour constituer la liste des fichiers .txt  

4    new Window('dialog' avec une 'dropdownlist' (présélectionner
      le fichier 'myDoc-changed.txt' si il existe ou ajouter son nom en début de cette liste et le sélectionner).  

5    L'utilisateur peut choisir un autre fichier dans la liste ou
      valider la sélection.  

6    Deux boutons radio append et replace.  

7    Ajouter un champ 'If other file name' pour créer un nouveau
      fichier (si ce champ et rempli le fichier et créer en priorité)  

Remarques :

      Pour créer un nouveau fichier vide, utiliser open('w')

      Je ne sais pas si la liste est longue ou pas ?  

J'ai fait un script de test qui semble fonctionner (si intéressé, me contacter par mail voir mon profil)

LR

Translate
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 ,
Jan 05, 2019 Jan 05, 2019

Hi,

many thanks - this seems to be a good way to handle the situation. It does not handle the situation where the user wants to use the suggested name but place the file in a subfolder, but since the actual script user has not asked for that feature so far, I am happy with it

Translate
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
Advocate ,
Jan 09, 2019 Jan 09, 2019
LATEST

Hi !

Subfolders, this is not a problem just integrate everything in the dialog.

(ListBox is more presentable see link)

https://share.orange.fr/#iFX0IN6EOU14fb83a847

LR

Translate
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