Copy link to clipboard
Copied
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....
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
...Copy link to clipboard
Copied
can you share your code or maybe a screencapture of the behavior you're describing? i'm not following.
Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now