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

PromptToSaveChanges / ScriptUI Default Highlighted Button

Participant ,
Aug 07, 2016 Aug 07, 2016

Copy link to clipboard

Copied

Hi!

For some reason when I try to close a document using SaveActions.PROMPTTOSAVECHANGES, the prompt never appears and it autosaves and closes. As a workaround, I've just built my own dialog using ScriptUI, but for some reason I can't figure out how to set the OK button to be highlighted by default like the AI prompt.

Untitled-2.jpg

Untitled-1.jpg

var dlg = new Window('dialog', 'Save Changes?');

dlg.orientation = 'column';

dlg.add( 'staticText', undefined, 'Save changes to ' + doc.name + ' before closing?' );

var btnGrp = dlg.add( 'group' );

var yes = btnGrp.add( 'button', undefined, 'Yes' );

var no = btnGrp.add( 'button', undefined, 'No' );

btnGrp.add( 'button', undefined, 'Cancel' );

dlg.defaultElement = yes;

dlg.show;

If you have could point me in the right direction in either, I'd really appreciate it!  Thanks!

TOPICS
Scripting

Views

755

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

Community Expert , Aug 07, 2016 Aug 07, 2016

no idea.

But this could be a workaround:

yes.active = true;

yes.active = false;

yes.active = true;

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 07, 2016 Aug 07, 2016

Copy link to clipboard

Copied

Try

yes.active = true;

And do not forget the brackets after show()

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
Participant ,
Aug 07, 2016 Aug 07, 2016

Copy link to clipboard

Copied

Thank you so much!  I don't know how I missed that!

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
Participant ,
Aug 07, 2016 Aug 07, 2016

Copy link to clipboard

Copied

Follow up q:

That did the trick in terms of highlighting the Yes button, but for some reason I still have to hit Tab twice before it will move the selection to the 'No' button. I'm currently running Illustrator CC 2015.2.0, 19.2.0 64bit on Windows 7. Thanks again for your help!

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 ,
Aug 07, 2016 Aug 07, 2016

Copy link to clipboard

Copied

no idea.

But this could be a workaround:

yes.active = true;

yes.active = false;

yes.active = true;

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
Participant ,
Aug 07, 2016 Aug 07, 2016

Copy link to clipboard

Copied

Love it! Thanks again!

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
Valorous Hero ,
Aug 07, 2016 Aug 07, 2016

Copy link to clipboard

Copied

SaveActions.PROMPTTOSAVECHANGES

Should it not be instead "SaveOptions" ?

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
Participant ,
Aug 08, 2016 Aug 08, 2016

Copy link to clipboard

Copied

Man, two for two on silly mistakes 9.9. SaveOptions did the trick, thanks!

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
Participant ,
Aug 08, 2016 Aug 08, 2016

Copy link to clipboard

Copied

Have you noticed the PROMPTTOSAVECHANGES acting buggy at all? For some reason it will work correctly once or twice and then just bypass the dialog and auto-save. ¯\_(ツ)_/¯

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
Valorous Hero ,
Aug 08, 2016 Aug 08, 2016

Copy link to clipboard

Copied

One question - was there any chance that the document in question in such a state that there were no unsaved changes at the time of closing?  But yea I never used that option in all my years yet.

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
Participant ,
Aug 08, 2016 Aug 08, 2016

Copy link to clipboard

Copied

Nope, I've got a conditional

if( doc.saved ) {

    doc.close( SaveOptions.DONOTSAVECHANGES );

}

else {

    doc.close( SaveOptions.PROMPTTOSAVECHANGES );

}

C'est la vie~

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
Valorous Hero ,
Aug 08, 2016 Aug 08, 2016

Copy link to clipboard

Copied

I do agree that this makes sense what you put forth, however in the conditional there's really no way to tell if one statement was executed rather than the other successfully, or vice-versa with error. Could it be that some of the preceding actions did change the document but its status was not updated yet? When this kind of stuff comes up, I generally stick an alert to make sure I'm sure.

Hmm, not sure if UserInteractionLevel would affect this either, if that is in play.

And, I also notice some strange bugs in my work when I have been using my application instance for testing and getting errors- then sometimes following runs will be affected by my previous work, so I also try to restart my AI every once in a while and I find some of the errors are gone with a fresh instance. Just some thoughts- always good to know about more weird Illustrator stuff!

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
Participant ,
Aug 08, 2016 Aug 08, 2016

Copy link to clipboard

Copied

Interesting... I feel like the 'saved' property usually corresponds to whether the filename has an asterisk next to it in the tab or not.

Untitled-1.jpg

I've found that the SAVECHANGES and DONOTSAVECHANGES both seem to work pretty consistently, and when the prompt doesn't pop up the file gets overwritten, but I'll try sticking some alerts in there just to make sure. Still v strange...

I haven't gotten to the point of restarting AI (yet), but I have added in chunks of code to try cutting and pasting everything and rerunning the script when it encounters a weird error haha.

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
Valorous Hero ,
Aug 08, 2016 Aug 08, 2016

Copy link to clipboard

Copied

The nature of bugs is so tricky, it could be anything- for example, I just thought of this - could your "doc" variable be perhaps referencing any older instance of a document? Also, I wrap each and every one of my scripts, including any snippets ran, into a function-closure to help avoid global variables. If there's a global doc variable from scripts ran previously, maybe it affects the saving.

Well I finally tested this for myself and I did so by hiding/showing a layer in script to make sure the saved status really changes - and it does appear to correctly reflect this every time. However when the Cancel button is pressed, an error is returned. I guess they want to wrap it into a try/catch to give you ability to continue with the flow of script if someone does a Cancel.

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
Participant ,
Aug 08, 2016 Aug 08, 2016

Copy link to clipboard

Copied

Sorry I should have mentioned that, I stripped down that snippet for clarity. I have that inside a function and this is the full code. I hit that Cancel error too, interesting way to do it but whatever works.

function DeleteAndClose() {

    if( !app.documents.length ) return;

    var doc = app.activeDocument;

   

    if( doc.name == 'PO.pdf' ) {

        doc.selectObjectsOnActiveArtboard();

       

        if( doc.selection.length > 0 )

            app.cut();

       

        if( app.documents.length > 1 )

            app.documents[1].close( SaveOptions.DONOTSAVECHANGES );

    }

    else {

        if( doc.saved ) {

            doc.close( SaveOptions.DONOTSAVECHANGES );

        }

        else {

            /*try {

                doc.close( SaveOptions.PROMPTTOSAVECHANGES );

            }

            catch( err ) { }

            */

           

            var dlg = new Window('dialog', 'Save Changes?');

            dlg.orientation = 'column';

           

            dlg.add( 'staticText', undefined, 'Save changes to ' + doc.name + ' before closing?');

           

            var btnGrp = dlg.add( 'group' );

            var yes = btnGrp.add( 'button', undefined, 'Yes' );

            var no = btnGrp.add( 'button', undefined, 'No' );

            btnGrp.add( 'button', undefined, 'Cancel' );

            dlg.defaultElement = yes;

            yes.active = true;

            yes.active = false;

            yes.active = true;

           

            yes.onClick = function() {

                dlg.close();

               

                var fullPath = doc.fullName.toString();

                var parDir = fullPath.substr( 0, fullPath.lastIndexOf('/') ) + "/";

               

                if( parDir == '/c/Program%20Files/Adobe/Adobe%20Illustrator%20CC%202015/Support%20Files/Contents/Windows/' ) {

                    var fileName = fullPath.split( '/' );

                    fileName = fileName[ fileName.length-1 ];

                   

                    var savePath = new File( '~/' + fileName ).saveDlg("Choose PDF output folder:");

                    if( savePath == null ) return;

                   

                    pdfSaveOpts.generateThumbnails = true;

                    pdfSaveOpts.preserveEditability = true;

                    doc.saveAs( savePath, pdfSaveOpts );

                   

                    doc.close( SaveOptions.DONOTSAVECHANGES );

                   

                }

                else {

                    doc.close( SaveOptions.SAVECHANGES );

                }

            }

           

            no.onClick = function() {

                dlg.close();

                doc.close( SaveOptions.DONOTSAVECHANGES );

            }

           

            dlg.show();

        }

    }

}

DeleteAndClose();

I haven't had any issues with the dialog window yet which leads me to think that it is something weird about the PROMPT option.

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
Valorous Hero ,
Aug 08, 2016 Aug 08, 2016

Copy link to clipboard

Copied

LATEST

Okay, I see you are closing app.documents[1], which is not the active document, but it really shouldn't matter due to where it's located. Hmm oh well, same as you: shrug!

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